Search Posts

Category: xmlhttprequest

When timeout and when abort occur in $http.get?

AngularJS 1.6.6 has support for differentiation between XHR completion, error, abort, timeout, I have this code snippet which make a request to a url like below: $http.get(url, {timeout: 1000}) .then(…) .catch(function(error) { console.log(error.xhrStatus) // could be abort, complete, error and timeout }); When requesting my api takes more than 1 second the promise is rejected with xhrStatus of ‘abort’, I was wondering in what situation I will get ‘timeout’ and ‘error’ status texts? Source: AngularJS

Javascript scope variable [duplicate]

This question already has an answer here: How to return the response from an asynchronous call? 25 answers var preGameRequest = new XMLHttpRequest(); var preGameData;“GET”, “/matches/live.json”); preGameRequest.onload = function() { preGameData = JSON.parse(preGameRequest.responseText); } preGameRequest.send(); console.log(preGameData); // main problem is here Here is my code. I defined preGameData as global and tried to save /matches/live.json file’s data into preGameData. And when I try to console.log(preGameData) from outside of the scope (like in the code […]

error while perfomin get operation using XHRHttprequest in angularjs

I am trying retrieve data from a web service. when i try to do it via ARC i am getting the following error if USE XHR is enabled then i am getting data in the form of JSON. Is there any way to do it programatically using angular2? my final output should be in the form of object. var xhr = new XMLHttpRequest(); xhr.timeout = 2000; xhr.onreadystatechange = function(e){ if (xhr.readyState === 4){ if (xhr.status […]