有什么办法让跨服务器ajax调用?

时间:2011-08-12 03:01:13

标签: ajax cross-domain

我正在学习XML,并且我找到了一个拥有XML Feed的网站。我想弄清楚是否有办法让跨服务器ajax调用?

我正在使用的代码如下:

<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>

1 个答案:

答案 0 :(得分:2)

您制作跨域ajax请求(我知道)的唯一方法是:

  1. 使用JSONP
  2. 使用代理
    • 与此相关的替代方法可能是使用Google Feed API(或类似服务)
  3. 如果服务器支持(并且您通常需要控制服务器),请使用access control headers
  4. 在这种情况下,看起来你不能做任何这些,所以你运气不好。