可以从远程服务器AJAX请求的数据? [英] Can AJAX request data from a remote server?

查看:275
本文介绍了可以从远程服务器AJAX请求的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用XMLHtt prequests在JavaScript要求在不同的服务器上的文件不是从发出请求,其中之一?

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来减少你的网页和服务器之间的code和忧虑,和所有你需要做的是:

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆