TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Async GET Call using Fetch API in JavaScript
Ashish Vishwakarma
Nov 02
2015
Code
1.2
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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