Wednesday, 15 February 2012

jQuery load external site page -



jQuery load external site page -

is possible load single page external website?

i trying show single page cannot seem work

$("#response").load("http://domain.com", function(response, status, xhr) { if (status == "error") { var msg = "sorry there error: "; alert(msg + xhr.status + " " + xhr.statustext); } });

help appreciated

you're running cross domain policy issue cause ajax (for security reasons) not allow grab content page not sit down on same domain.

to rid of , accomplish task: need php file can phone call grabber.php line of php:

<?php echo file_get_contents($_get['url']); ?>

than within html (or whatever file like:)

<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <meta charset=utf-8 /> <title>test</title> </head> <body> <div id="response"></div> </body> <script> $(function(){ var contenturi= 'http://domain.com #element'; // url grab + # of desired element // if needed :) $('#response').load('grabber.php?url='+ contenturi); }); </script> </html>

why work?

now, ajax sending simple request grabber.php page, grabber.php echoes desired content now content on (server) domain! and ajax happy serve :)

jquery load

No comments:

Post a Comment