我可以使用XMLHtt prequest的不同端口上从该端口加载的脚本文件? [英] Can I use XMLHttpRequest on a different port from a script file loaded from that port?

查看:158
本文介绍了我可以使用XMLHtt prequest的不同端口上从该端口加载的脚本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站使用XMLHtt prequest(jQuery的,实际上)。我也有其他站点在同一台服务器,它提供一个脚本文件,使XHR请求返回到该网站,即上运行。

I have website that use XMLHttpRequest (jQuery, actually). I also have another site running on the same server, which serves a script file that makes XHR requests back to THAT site, ie.

的http:// mysite的:50000 / index.html的 包括

http://mysite:50000/index.html includes

<script src="http://mysite:9000/otherscript.js"></script>

的http:// mysite的:9000 / otherscript.js 包括

and http://mysite:9000/otherscript.js includes

$.ajax({
    url: 'http://mysite:9000/ajax/stuff'
});

现在的问题是 - 这是行不通的。从加载脚本的AJAX请求根本没有失败,错误消息。从我已经能够发现这是旧的同源策略。鉴于我控制这两个网站,有什么我可以做,使这项工作?而document.domain的招似乎并没有做任何事情的XMLHtt prequest。

The problem is - this doesn't work. The AJAX requests from the loaded script simply fail with no error message. From what I've been able to find this is the old same origin policy. Given that I control both sites, is there anything I can do to make this work? The "document.domain" trick doesn't seem to do a thing for XMLHttpRequest.

推荐答案

Nope-不能XHR做到这一点。同域策略是非常严格的there-同一主机,同一端口,相同的协议。抱歉!你将不得不诉诸其他技巧(内部框架,标题操作等),以得到它的工作。

Nope- can't do this with XHR. Same-domain policy is very restrictive there- same host, same port, same protocol. Sorry! You'll have to resort to other tricks (iframes, title manipulation, etc) to get it to work.

这篇关于我可以使用XMLHtt prequest的不同端口上从该端口加载的脚本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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