jQuery的跨站取 [英] jQuery Cross Site Fetch

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

问题描述

我觉得这是很容易,但我失去了一些东西......

I feel like this is easy but I am missing something...

使用jQuery,我试图获取远程页面(在不同的服务器上),捕捉到的HTML内容,并注入该内容到一个隐藏的DIV。但是,无论是使用$阿贾克斯或$不用彷徨导致在Firefox中的跨站点脚本错误。

Using jQuery, I am trying to fetch a remote page (on a different server), capture the HTML contents, and inject that content into a hidden DIV. However, using either $.ajax or $.get results in a cross-site scripting error in FireFox.

有什么建议? code:

Any suggestions? Code:

$.ajax({
    type: 'GET',
    url: "http://www.remote-url.com",
    dataType: 'html',
    success: function(data) {
        $('#put_here').empty().append(data);
    }
});

谢谢!

乍得

推荐答案

您不能做到这一点 - 在的同源策略 prevents它出于安全原因(如你发现)。

You can't do that - the Same Origin Policy prevents it for security reasons (as you've found).

您需要运行一个代理脚本的,你的JavaScript使用,以获取自己的服务器上从代表的远程服务器的内容。

You need to run a proxy script on your own server that your JavaScript uses to fetch the content from the remote server on its behalf.

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

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