JQuery $.get() question
Ive got the following question and im trying to figure out the answer:
You can find the following code here: http://7.testaddress.com/test.php Do you think the code will work, explain?
$.get('http://1.testaddress.com/ajax/remote.php?id='+id, responseCallback);
Is the answer no it wont work because its not located at the same add开发者_开发技巧ress?
Yes it wont work because it is from a different sub-domain. At the bottom of the bottom of the jQuery documentation for the Get method there's this little chestnut:
Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.
I believe JQuery has a type of ajax request called JSONP ... which would enable you to do cross domain ajax requests.
http://api.jquery.com/jQuery.getJSON/
精彩评论