I'm trying to request data which is located on another domain/server, but I'm getting an exception when I try to send the request.
var request = new XMLHttpRequest();
request.open("GET", "http://www.w3schools.com/ajax/cd_catalog.xml", false);
request.send();
The error:
uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)"]
Is this the correct way to request content which isn't on the same domain/server? Or is there some other way to accomplish this?
I'm testing this in firefox 8.0, but I'd like a solution that could work for all major modern browsers.
This is called Cross-Domain Ajax most browsers consider this a security violation. One workaround is to create a server side component (the same domain as the page you are viewing) that will request the data from the other server (/www.w3schools.com in your case) and echo that back to your Ajax request.
these links will explain the problem and several solutions:
http://jimbojw.com/wiki/index.php?title=Introduction_to_Cross-Domain_Ajaxrequest
http://usejquery.com/posts/the-jquery-cross-domain-ajax-guide
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With