将外部div内容加载到我的页面div

时间:2012-10-17 15:56:25

标签: jquery load external

我正在尝试将外部网站#external-div内容加载到#mydiv div上的页面。我试过附上这个jquery

<script src="js/jquery-1.8.2.min.js"></script>

和脚本是

<script>
    $(document).ready(function(){
        $('#mydiv').load('http://localhost/qa/ask #external-div');
    });
</script>

我的div

<div id="mydiv">loading...</div>

我已经从这里下载了jquery http://jquery.com/download/?rdfrom=http%3A%2F%2Fdocs.jquery.com%2Fmw%2Findex.php%3Ftitle%3DDownloading_jQuery%26redirect%3Dno

但它没有加载任何东西。

1 个答案:

答案 0 :(得分:3)

尝试下面的代码以获得回调响应:

$('#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);
      }
});