jan tot
jan tot

Reputation: 23

Wordpress and javascript .load() function

I have problem to get .load() function working in Wordpress. Initially I was using 3.0.5 version of WP, wanted to get some content from external page (same domain), so I used this code

jQuery.noConflict();
 jQuery(document).ready(function(){
   jQuery(".someclass").load("http://www.mydomain.com #someid");
 });

...and it worked. However, after update of Wordpress to latest version (and installation of plugins /some use jquery or mootools/, this piece of code isnt pulling any content anymore. I tried to write different code for noConflict mode but also without success (but JS is working if I change line to some alert func). I also deactivated all plugins, removed other js (like for menu), but still no content was displayed. If I use same code in a separate file (in the same directory where WP theme is) - it works.

I would be thankful if someone have advice what to try next or where to look for potential problem. Or maybe to suggest some other approach how to get content from external page (and specific div). If I put that separate file into iframe and call it within sidebar, it's working but then there's a problem of iframe links opening within iframe box.

Upvotes: 2

Views: 292

Answers (1)

Dunhamzzz
Dunhamzzz

Reputation: 14798

Your problem is the same origin policy, which in lamens terms means you can't do ajax requests to different domains (even subdomains) as it is security risk, you browser simply won't let you do it. Specifically in your case you are attempting to load www.infostar.rs from inforstar.rs.

You will need to come up with another idea, personally I would just do it in PHP with:

 echo file_get_contents('http://domain.com');

Alternatively would could look into forcing non-www in htaccess.

Upvotes: 3

Related Questions