调用外部Web页面(跨域)的JavaScript [英] Call a external web page (cross-domain) with javascript

查看:142
本文介绍了调用外部Web页面(跨域)的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证饲料,使用Web服务,是在的这个问题

I'm trying to validate a feed, using the web service that is in this question.

不过,浏览器不允许我送一个AJAX的GET请求到另一台服务器。还有就是每个在Web服务的每个请求一秒的限制,所以我不能反映从我的服务器的请求。

But browser does not allow me to send a ajax GET request to another server. And there is a one second restriction per each request in that web service, so I can't mirror requests from my server.

这是我目前的jQuery code:

This is my current jQuery code:

var reqUrl = "http://validator.w3.org/feed/check.cgi?url=" + encodeURIComponent(theUrl);
$.get(reqUrl, function(data) {
    // do something
});

没有任何其他的方式?

Isn't there any other way?

推荐答案

除非你使用Ajax调用不能跨不同的域有效的 JSONP 。 <一href="http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain">JQuery-ajax-cross-domain是一个类似的问题,可能会给你一些见解。另外,作为在评论中指出的路易斯,JSONP已到还可以在你得到的数据域实现的。

Ajax calls are not valid across different domains unless you use JSONP. JQuery-ajax-cross-domain is a similar question that may give you some insight. Also as noted by Luis in the comments, JSONP has to also be implemented on the domain that you are getting the data from.

下面是jQuery的阿贾克斯()的一个例子,但你可能想看看 $ .getJSON( )

Here is an example for jquery ajax(), but you may want to look into $.getJSON():

$.ajax({
    url: 'http://yourUrl?callback=?',
    dataType: 'jsonp',
    success: processJSON
});

另一种选择是 CORS 的(交叉来源资源共享),但是,这要求其他服务器,以使CORS其中最有可能不会发生这种情况。

Another option is CORS (Cross Origin Resource Sharing), however, this requires that the other server to enable CORS which most likely will not happen in this case.

这篇关于调用外部Web页面(跨域)的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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