Javascript obeys the same domain policy. This means that JS Script in the clientβs browser can only work in the same domain as it is.
JSONP does not fall under the same restrictions.
Check out jQuery docs for JSONP here:
http://api.jquery.com/jQuery.getJSON/
Here is an example of using JSONP to access a cross-domain service through jQuery AJAX:
http://jsbin.com/idasay/4
And just in case, JSBIN will remove this paste in the future:
jQuery.ajax({ type: "GET", url: 'http://api.geonames.org/postalCodeLookupJSON?postalcode=6600&country=AT&username=demo', dataType: "jsonp", cache: false, crossDomain: true, processData: true, success: function (data) { alert(JSON.stringify(data)); }, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("error"); } });
source share