Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
146
rated 0 times [  153] [ 7]  / answers: 1 / hits: 17824  / 14 Years ago, wed, march 16, 2011, 12:00:00

Requesting data from any location on my domain with .load() (or any jQuery ajax functions) works just fine.



Trying to access a URL in a different domain doesn't work though. How do you do it? The other domain also happens to be mine.



I read about a trick you can do with PHP and making a proxy that gets the content, then you use jQuery's ajax functions, on that php location on your server, but that's still using jQuery ajax on your own server so that doesn't count.



Is there a good plugin?



EDIT: I found a very nice plugin for jQuery that allows you to request content from other pages using any of the jQuery function in just the same way you would a normal ajax request in your own domain.



The post: http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/



The plugin: https://github.com/jamespadolsey/jQuery-Plugins/tree/master/cross-domain-ajax/


More From » jquery

 Answers
155

This is because of the cross-domain policy, which, in sort, means that using a client-side script (a.k.a. javascript...) you cannot request data from another domain. Lucky for us, this restriction does not exist in most server-side scripts.



So...



Javascript:



$(#google-html).load(google-html.php);


PHP in google-html.php:



echo file_get_contents(http://www.google.com/);


would work.


[#93259] Monday, March 14, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kenyonmasonc

Total Points: 44
Total Questions: 117
Total Answers: 116

Location: Morocco
Member since Fri, May 22, 2020
4 Years ago
;