[英]XMLHttpRequest Origin is not allowed by Access-Control-Allow-Origin
I'm trying to fetch some simple text over HTTP from JavaScript: 我正在尝试通过JavaScript从HTTP获取一些简单的文本:
$(function() {
$.get("http://mydomain.com/path", function(result) {
console.log(result);
});
});
The result should be text/html
, but is basically only a simple key-value string, no HTML tags whatsoever. 结果应该是
text/html
,但基本上只是一个简单的键值字符串,没有任何HTML标签。 The page is in my control, but is supplied by a third-party (closed-source) so I can't modify the Java that serves out this page. 该页面在我的控制下,但由第三方(封闭源)提供,因此我无法修改为该页面提供服务的Java。
How can I get the contents of this page from JavaScript? 如何从JavaScript获取此页面的内容?
You've simply gotta use either PHP/ASP your serverside language to retrieve the cross-domain request or use a service such as a cross domain ajax service created by Yahoo!. 您只需使用
PHP / ASP 服务器语言来检索跨域请求,或者使用诸如Yahoo!创建的跨域ajax服务之类的服务。
It uses JSONP which is allowed to do very strict cross-domain requests, but asking from Yahoo! 它使用JSONP,可以执行非常严格的跨域请求,但可以向Yahoo!询问。 they will retrieve any page on the internet.
他们将检索互联网上的任何页面。
http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/ http://james.padolsey.com/javascript/cross-domain-requests-with-jquery/
You can't request that page because of Same Origin Policy unless that page has explicitly allowed you with CORS . 除非该页面明确允许您使用CORS,否则您不能因为“ 同源政策”而请求该页面。
Either proxy it server side, with a service such as YQL, get it as JSONP or get the other service to enable CORS for your domain. 使用服务(例如YQL)在服务器端代理它,将其获取为JSONP或获取其他服务以为您的域启用CORS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.