ajax跨域调用
我是 ajax 新手,
我正在尝试从 url: 获取数据:
http://202.65.151.110:8080/ShreeMobileWeb/priceupdate" + "?d=" + "2%2C"+ "" + "%2C" + "150" +"%2C" + "100" +"%2C" +"N-A" +"%2C" +"N-A";
并且我的应用程序也在同一服务器上 202.65.151.110
但我仍然收到错误:
来源 http://202.65.151.110 不允许 访问控制允许来源。
I am new to ajax
I am trying to get data from the url:
http://202.65.151.110:8080/ShreeMobileWeb/priceupdate" + "?d=" + "2%2C"+ "" + "%2C" + "150" +"%2C" + "100" +"%2C" +"N-A" +"%2C" +"N-A";
and my application is also on the same server 202.65.151.110
but I still get error:
Origin http://202.65.151.110 is not allowed by
Access-Control-Allow-Origin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您不能按照 向不同的服务器(主机和端口)发出 AJAX 请求同源策略。解决方案是使用脚本注入或者使用 JSONP
You cannot make an AJAX request to a different server (host AND port) as per the same origin policy. The solution is to use script injection or use JSONP
你使用同一个端口吗?它可能尝试访问 http://202.65.151.110:80,但不是 http://202.65.151.110:8080 或反之亦然。
do you use the same port? it is possible that it tries to access to http://202.65.151.110:80, but not http://202.65.151.110:8080 or vice versa.
来源包括端口以及主机名和 IP 地址。
The origin includes the port as well as the hostname and ip address.
其他人都说了,但看看 postMessage,它允许您使用 JavaScript 进行跨域通信: https://developer.mozilla.org/en/DOM/window.postMessage
What everyone else said, but have a look at postMessage, which allows you to do cross-domain communication with JavaScript: https://developer.mozilla.org/en/DOM/window.postMessage
Google Feed API 可以将任何常规 XML feed 改编为 JSONP feed。
http://code.google.com/apis/feed/v1/
The Google Feed API can adapt any regular XML feed into a JSONP feed.
http://code.google.com/apis/feed/v1/
您可以使用代理 -> http://devtreats.blogspot.com/2011/01/cross-domain -ajax.html
You could use a proxy -> http://devtreats.blogspot.com/2011/01/cross-domain-ajax.html