我可以通过AJAX加载从外部页数据? [英] Can I load data from an external page via AJAX?

查看:85
本文介绍了我可以通过AJAX加载从外部页数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习jQuery和AJAX。我可以通过来加载本地页面(在我的硬盘)插入一个div jQuery.load(),但外部网站似乎并没有工作。我甚至使用Wireshark来检查数据正在从服务器(这是)发送。样品code是如下:

I've just starting learning jQuery and AJAX. I'm able to load a local page (on my disk) into a div via jQuery.load(), but external sites don't seem to work. I've even used wireshark to check if the data is being sent from the server (it is). Sample code is below:

<html>
<head>
    <script src='jquery-1.4.2.min.js'></script>
    <script>
        $(document).ready(function() {
            // $('#test').load('localpage.htm'); works!
            $('#test').load('http://www.google.com/'); // does not work!
        });
    </script>
</head>
<body>
<div id='test'></div>
</body>
</html>

是否有可能做到这一点摆在首位?如果是这样,怎么样?

Is it possible to do this in the first place? If so, how?

推荐答案

开箱:没有。这是一个安全问题。有href="http://www.ajax-cross-domain.com/" rel="nofollow">几个的不同 的解决方法虽然。

Out of the box: no. It's a security issue. There are a few different workarounds though.

这篇关于我可以通过AJAX加载从外部页数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆