tags:

views:

447

answers:

4

Why does jQuery.ajax() throw an error with no error message if you use a URL with a dfferent server?

+5  A: 

I believe you'll find this helpful:

http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html

Nathan Loding
+7  A: 

Its because of the restriction on cross domain requests implemented in the browser for XMLHttpRequests. You can get around this by using JSONP as the format, otherwise you'll need a server-side proxy for the request.

Quoting from the ajax documentation on http://jquery.com

Note: All remote (not on the same domain) requests should be specified as GET when 'script' or 'jsonp' is the dataType (because it loads script using a DOM script tag). Ajax options that require an XMLHttpRequest object are not available for these requests. The complete and success functions are called on completion, but do not receive an XHR object; the beforeSend and dataFilter functions are not called.

tvanfosson
+1  A: 

The ajax() method internally uses XmlHttpRequest which obeys the same domain policy http://en.wikipedia.org/wiki/Same_origin_policy. The getJson() method can be used instead for making cross domain calls.

I hope this helps, Bogdan

BBz
A: 

Because if Same Origin Policy jQuery will not allow this. The best option will be using some proxy server page to get the required pages.

Maksud