jQuery 将外部 div 内容加载到我的页面 div
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12938386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Load external div content to my page div
提问by Code Lover
I am trying to load external website #external-div content to the page on #mydiv div. I have tried by attaching this jquery
我正在尝试将外部网站 #external-div 内容加载到 #mydiv div 上的页面。我已经尝试通过附加这个 jquery
<script src="js/jquery-1.8.2.min.js"></script>
<script src="js/jquery-1.8.2.min.js"></script>
and script is
和脚本是
<script>
$(document).ready(function(){
$('#mydiv').load('http://localhost/qa/ask #external-div');
});
</script>
My div
我的div
<div id="mydiv">loading...</div>
<div id="mydiv">loading...</div>
I have downloaded jquery from here http://jquery.com/download/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DDownloading_jQuery%26redirect%3Dno
我已经从这里下载了 jquery http://jquery.com/download/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DDownloading_jQuery%26redirect%3Dno
But its not loading anything.
但它没有加载任何东西。
回答by Habibillah
try code bellow to get callback respon:
尝试以下代码以获取回调响应:
$('#mydiv').load('http://localhost/qa/ask #external-div', function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
alert(msg + xhr.status + " " + xhr.statusText);
}
});