Why can't I load Flickr.com using jQuery .load method?
My HTML code is:
<!DOCTYPE html>
<meta charset="utf-8">
<title>Untitled Document</title>
<script 开发者_运维百科src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<div id="abc"></div>
<script>
$('#abc').load('http://www.flickr.com/');
</script>
But in , there's nothing.
Where is error?
Thank you!
The .load()
function uses AJAX. AJAX doesn't work cross-domain, this is why it isn't working.
You can however use JSONP to retrieve Flickr data: http://api.jquery.com/jQuery.getJSON/
You cannot load external sites (different domain) via jQuery, unless your using the JSON functions.
As mentioned before, you can't use the load
function for pages outside your own domain. But you could use an iframe instead:
<iframe id="abc"></iframe>
<script language="javascript" type="text/javascript">
$('#abc').attr('src', 'http://www.flickr.com');
</script>
精彩评论