JQuery not working

I have a javascript part that captures JSON data. When executed locally, everything works fine. However, when I try to access it from another site, it does not work.

Here is the script.

$(function(){ var aT = new AjaxTest(); aT.getJson(); }); var AjaxTest = function() { this.ajaxUrl = "http://mydeveloperpage.com/sandbox/ajax_json_test/client_reciever.php"; this.getJson = function(){ $.getJSON(this.ajaxUrl, function(data){ $.each(data, function(i, piece){ alert(piece); }); }); } } 

You can find a copy of the same file under http://mydeveloperpage.com/sandbox/ajax_json_test/ ".

Any help would be greatly appreciated.

Thanks!

+1
source share
1 answer

From the documentation :

  • Due to browser security restrictions, most Ajax requests are subject to the same origin policy; The request cannot successfully retrieve data from another domain, subdomain, or protocol.

  • Script, and JSONP requests do not fall under the same origin policy restrictions.

You will need to use JSONP to go through a policy of the same origin. jQuery can make this seamless (see the rest of the above documentation page).

+3
source

Source: https://habr.com/ru/post/1337267/


All Articles