问题
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:
- 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.
来源:https://stackoverflow.com/questions/7035169/any-way-to-make-cross-server-ajax-calls