AJAX 可以从远程服务器请求数据吗? [英] Can AJAX request data from a remote server?
本文介绍了AJAX 可以从远程服务器请求数据吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以在 JavaScript 中使用 XMLHttpRequests 来请求与发出请求的服务器不同的服务器上的文件吗?
Can I use XMLHttpRequests in JavaScript to request a file on a different server than the one from where the request was made?
谢谢.
推荐答案
您需要使用一种称为 JSONP.
You need to use a method that is called as JSONP.
最好的方法之一是使用 jQuery 来减少您的页面和服务器之间的代码和烦恼,您需要做的就是:
One of the best ways is to use jQuery to reduce the code and worries between your page and the server, and all you need to do is:
$.ajax({
dataType: 'jsonp',
data: 'id=10',
jsonp: 'jsonp_callback',
url: 'http://myotherserver.com/getdata',
success: function () {
// do stuff
},
});
这篇关于AJAX 可以从远程服务器请求数据吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文