Search Posts

Category: xmlhttprequest

Do detect as compelleted before runing an XHR in a controller Angularjs

I have an application which is using Angularjs. In each controller, I have a function that should run on route loading. I mean I want a constructor function in my controller. I want that the browser does not mark the page az completed page (ready document) before finishing that XHR request. The reason is I`m using a system to render HTML snapshot of my pages, and I want to tell Phantomejs that the page is […]

$http.get does not call the backend if called twice to quick

I have a case in AngularJS where if I call the $http.get(‘/sameresource’) for the same resource method twice fast one after the other, then I see (from debugging) that the backend is called only one time, although when I debug in Firefox (or Chrome) it seems that the second call works, and the callback is then also called. It is supposed that the first call to make some changes in the backend and so should […]

Cant perform HTTP request in angular JS [duplicate]

This question already has an answer here: XMLHttpRequest cannot load https://www.[website].com/ 6 answers In my javascript code am trying to perform a GET HTTP request on an angular app. The request will comunicate with Qlik sense server, but i always get a 401 error (unauthorized). I performed the same get request on Postman and it retrieved the data. In and the error says Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header […]

Consume same WCF service from angular 2 and Silverlight application

Currently we have one Silverlight application (frontend) with WCF services (backend). Now, we are going replace the Silverlight application with an Angular 2 application without changing the WCF services – only the UI will get changed. Before starting with Angular 2, we have created a demo application in Angular 2 to verify that WCF services are working with Angular 2, because Silverlight supports basicHttpBinding and for Angular 2, we need to use webHttpBinding. Currently we […]

XMLHttpRequest.t.onload and $rootScope:infdig

how to XMLHttpRequest.t.onload and $rootScope:infdig I build a website by mean-stack. In the controller of a page, I have the following code linked to a button: $scope.addFolder() = function () { $‘/httpOnly/posts/test’, {}, { headers: { Authorization: ‘Bearer ‘ + auth.getToken() } } ) .then(function () { $window.location.href = “https://localhost:3000/help” } } and in the backend, I have“/httpOnly/posts/test”, auth, function (req, res, next) { return res.json(null) }) Clicking on the button does redirect to […]

Checking if your pdf download is complete and then opening it directly using javascript

I’m developing a cross platform app using cordova. I use intel XDK as a simulator. I want to download a pdf file from webservice and open it once it gets downloaded. I have used the following code var xhr = new XMLHttpRequest();“GET”, mapusaurl); xhr.setRequestHeader(‘Authorization’,auth); xhr.responseType = “arraybuffer”; xhr.onload = function () { if (this.status === 200) { var blob = new Blob([xhr.response], {type: “application/pdf”}); var objectUrl = URL.createObjectURL(blob); var link=document.createElement(‘a’); link.href=window.URL.createObjectURL(blob);”mapusa” + new […]

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 […]