Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Async GET Call using Fetch API in JavaScript
WhatsApp
Ashish Vishwakarma
Nov 02
2015
1.3
k
0
0
Fetch API is replacement for XmlHttpRequest with simple syntax returning Promise object which makes async call chaining simpler. Here examples is showing GET call using fetch, you can use other HTTP verbs as well.
fetch(
'http://jsonplaceholder.typicode.com/users/5'
,
{
method:
'get'
})
.then(function (pending)
{
return
pending.json();
//returning response as json after completion of async call, you can use .text() instead to return response as text
})
.then(function (response)
{
console.log(response);
//recieved GET response
})
.
catch
(function (error)
{
console.log(error);
//Handle any error here
});
JavaScript
Async GET Call
Fetch API in JavaScript
Up Next
Async GET Call using Fetch API in JavaScript