任何方式进行跨服务器的Ajax调用? [英] Any way to make cross server ajax calls?
本文介绍了任何方式进行跨服务器的Ajax调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我学习XML我发现一个网站,有一个XML饲料。我试图找出是否有一种方法来进行跨服务器的Ajax调用?
在code我现在用的就是如下:
< HTML>
< HEAD>
&所述;脚本的src =的http://$c$c.jquery.com/jquery-latest.js>&所述; /脚本>
< /头>
<身体GT;
<脚本>
$阿贾克斯({
键入:GET,
网址:http://www.nfl.com/liveupdate/scorestrip/ss.xml
数据类型:XML,
成功:函数(XML){
//国米preT响应
$(XML).find('G')。每个(函数(){
//例:显示在控制台中的XML标记
执行console.log(本);
//例:把一些输出的DOM
$(#divOutput)追加($(本).attr(HNN))。
});
$(XML).find('G')。每个(函数(){
//例:把一些输出的DOM
$(#divOutput)追加($(本).attr(K))。
})
}
});
< / SCRIPT>
< DIV ID =divOutput>< / DIV>
< /身体GT;
< / HTML>
解决方案
的唯一途径为你做跨域Ajax请求(即我所知道的)是:
在这种情况下,它看起来像你不能做任何这些,所以你的运气了。
I am learning XML and I've found a website that has a XML feed. I am trying to figure out if there is a way to make cross server ajax calls?
The code I am using is below:
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<script>
$.ajax({
type: "GET",
url: "http://www.nfl.com/liveupdate/scorestrip/ss.xml",
dataType: "xml",
success: function(xml) {
// Interpret response
$(xml).find('g').each(function() {
// Example: Show the XML tag in the console
console.log(this);
// Example: Put some output in the DOM
$("#divOutput").append($(this).attr("hnn"));
});
$(xml).find('g').each(function() {
// Example: Put some output in the DOM
$("#divOutput").append($(this).attr("k"));
})
}
});
</script>
<div id="divOutput"></div>
</body>
</html>
解决方案
The only ways for you to make cross domain ajax requests (that I'm aware of) are:
- Use JSONP
- Use a proxy
- A related alternative to this might be to use the Google Feed API (or similar service)
- If the server supports it (and you'll usually need to control the server), use access control headers
In this case, it looks like you can't do any of these, so you're out of luck.
这篇关于任何方式进行跨服务器的Ajax调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文