Browsers do not allow cross-domain AJAX calls. Only cross-domain JSONP requests are allowed.
To use JSONP requests, you must change the dataType property to jsonp . This means that you cannot request XML, but only JSONP.
A bit about JSONP:
The <script> bypasses restrictions between domains. This means that you can use this tag to receive data from other servers. This tag does not support all types of languages, therefore XML is not supported.
JSONP is basically JSON, but with a function call around it like this:
functionname({"property":"value"})
I see that you are wondering: "What is this function name doing there?"
This is EXACTLY the difference with JSON. Since the function is wrapped around it, you can use the actual data!
<script type="text/javascript"> var functionname = function(json) { alert(json.property); } </script> <script type="text/javascript" src="http://www.domain.com/jsonp"></script>
If you replace the second script tag with the content of the response, all of this will make sense:
<script type="text/javascript"> var functionname = function(json) { alert(json.property); } functionname({"property":"value"}); </script>
Believe it or not, this slight difference actually allows us to make cross-domain requests much safer.
Another thread about JSONP
source share