jQuery加载不起作用 [英] Jquery load doesn't work

查看:132
本文介绍了jQuery加载不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码中的jquery加载不起作用.我在这里想念的是什么?

The jquery load in the below code doesn't work. What I'm missing here?

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js">  </script>
</head>
<body style="font-size:62.5%;">

<div id="dialog" title="Dialog Title">I'm in a dialog</div>
<script>
$(document).ready(function() {
        $("#dialog").load('http://www.google.com/intl/en/about/index.html #maia-main');
});
</script>
</body>
</html>

推荐答案

您请求的页面位于其他域中,因此跨域策略适用.您只能在远程服务器允许的情况下跨域访问数据(我相信,只能使用JSONP,如果我对此有误,请纠正我).如果您想获取Google页面的源代码,则需要使用服务器端脚本作为jQuery的代理:

You are requesting a page that is on a different domain so Cross-Domain-Policies apply. You can only access data cross-domain if the remote-server allows it (and only using JSONP I believe, anyone please correct me if I'm wrong on this). If you want to grab the source of a Google page, you will need to do it with a server-side script as a proxy for your jQuery:

$(function() {

    //notice the client-side code (JS) is requesting a page on the save domain
    $("#dialog").load('my-script.php #maia-main');
});

my-script.php中,您将获取所需的远程页面:

And in my-script.php you would grab the remote page you want:

<?php

//PHP, like all server-side languages has no cross-domain-policy
echo file_get_contents('http://www.google.com/intl/en/about/index.html');
?>

file_get_contents()的文档: http://www.php.net/file_get_contents

这篇关于jQuery加载不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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