Question

hi i want to get a json file with xhr in xui and my code is this :

function getRequest()
{   
   x$().xhr('http://localhost:8080/DummyServer/login/request/',  
   {
      callback: function() 
      {
         saveLocalStorage(this.responseText);    
      },
   });
}   

I check with safari console, and I got an error like this :

XMLHttpRequest cannot load http://localhost:8080/DummyServer/login/request/. Origin http://localhost is not allowed by Access-Control-Allow-Origin.

but when i use coda ide there is no error, i wonder why. Anyone can help me with this xui.js?

Was it helpful?

Solution 2

finally i can do that with chrome and i disable the cross-domain security check for AJAX with open the chrome with this : /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security ( in windows ) and all that function run without any error for detail : http://opensourcehacker.com/2010/11/29/disabling-cross-domain-security-check-for-ajax-development-in-google-chrome/

OTHER TIPS

Same origin policy is enforced by the browser to protect websites from other websites making xhr requests and displaying their content as if it was their own.

So site A.com cannot connect to B.com with XHR or: http://A.com cannot connect to http://sub.A.com localhost:80 cannot connect to localhhost:8080

A way to deal with this is to use JSONP or CORS headers but CORS is not wel supported in IE<10.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top