You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perform a GET request to the given url, calling the callback when complete. If an error is encountered, the errback function will be called with an XhrError instance.
xhr(options, callback, errback)
Perform an HTTP requests with the given options, calling callback when complete. If an error is encountered, the errback function will be called with an XhrError instance.
options
The options object has the following properties:
url
The url to perform the request on.
method
The HTTP method to use (GET, POST, PUT, DELETE, etc.). Defaults to GET.
headers
An Object in which the keys are the header key and the values are the header value. Example
headers: {'Accept': 'application/json'}
data
The data to send along as the body of the request. For example, in a POST request.
credentials
If true, the withCredentials value will be applied to the XMLHttpRequest object, which allows for CORS requests.
Examples
varxhr=require('xhr');varfooData=JSON.stringify({foo: 'bar',baz: 'qux'});xhr({url: 'https://example.com/foos',headers: {'Content-Type': 'application/json','Content-Length': fooData.length},method: 'POST',data: fooData},functiononSuccess(){console.log('It worked!');},functiononError(err){console.log('There was an error: '+err.message);});