无法张贴在跨域使用JSONP数据 [英] Unable to post data using JSONP on Cross Domain

查看:116
本文介绍了无法张贴在跨域使用JSONP数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有我们需要从我们的域(x.com)POST数据到不同的域方案(y.com)。在y.com的行为被归结 HTTPPost ,它是可以改变的。但是,在使用数据发布到y.com AJAX JSONP 列举HTTPMethod POST 请求将被自动转换为列举HTTPMethod GET

We have a scenario where we need to post data from our domain (x.com) to a different domain (y.com). The action on the y.com is attributed HTTPPost and it can be changed. But while posting data to the y.com using AJAX and JSONP with HTTPMethod POST the request is automatically converted to HTTPMethod GET.

推荐答案

您不能发布使用 JSONP (看这里和<一个href=\"http://stackoverflow.com/questions/11736431/make-cross-domain-ajax-jsonp-request-with-jquery/11736771#11736771\">here)因为它只是<一个href=\"http://stackoverflow.com/questions/4508198/how-to-use-type-post-in-jsonp-ajax-call/4508215#4508215\">doesn't工作方式 - 它创建了一个&LT;脚本&GT; 元素来获取数据,其中有必须通过GET请求进行JSONP解决方案不使用<$。 C $ C> XmlHtt prequest 对象,所以它不是在理解的标准方式的AJAX请求,但内容仍是动态访问 - 为最终用户没有区别。

You can't POST using JSONP (look here and here) because it just doesn't work that way - it creates a <script> element to fetch data, which has to be done via GET request. JSONP solution doesn't use XmlHttpRequest object, so it is not an AJAX request in the standard way of understanding, but the content is still accessed dynamically - no difference for the end user.

JSONP可确实是用来克服同源策略的限制,但也可以使用< A HREF =htt​​p://en.wikipedia.org/wiki/Cross-origin_resource_sharing相对=nofollow> CORS ,在现代浏览器中实现<一个href=\"http://stackoverflow.com/questions/12296910/so-jsonp-or-cors/12309651#12309651\">alternative以JSON与填充。

JSONP can be indeed used to overcome same origin policy restriction, but alternatively you can use CORS, implemented in modern browsers alternative to JSON with Padding.

这篇关于无法张贴在跨域使用JSONP数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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