Javascript CORS Request -


i have php web service cors enabled.

i used http://www.test-cors.org/ confirm web service works. according service xhr load event fired , status code 200.

i copied code test cors generates online javascript console https://repl.it/languages/javascript

here receive 0 xhr status.

based on test cors web service set allow cross origin. when use online javascript console same web service returns status code of 0.

is there reason why code not work?

var createcorsrequest = function(method, url) {     var xhr = new xmlhttprequest();      if ("withcredentials" in xhr) {      //this part called correctly      xhr.open(method, url, true);     }       return xhr; };  var url = <url> var method = 'get'; var xhr = createcorsrequest(method, url);  xhr.loadstart = function() {     //not called } xhr.onload = function() {     //not called };  xhr.onerror = function() {     // called };  xhr.send();  alert(xhr.status) 

your alert of status made before send (thus receive) request, status not yet set , 0. of alerts/checks need inside onload/onerror, executed when request complete.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -