Any way to make cross server ajax calls?

北城以北 提交于 2019-12-11 10:05:30

问题


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>

回答1:


The only ways for you to make cross domain ajax requests (that I'm aware of) are:

  1. Use JSONP
  2. Use a proxy
    • A related alternative to this might be to use the Google Feed API (or similar service)
  3. 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.



来源:https://stackoverflow.com/questions/7035169/any-way-to-make-cross-server-ajax-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!