本文介绍了无法张贴在跨域使用JSONP数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我们有我们需要从我们的域(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 (看这里和here)因为它只是doesn't工作方式 - 它创建了一个&LT;脚本&GT; 元素来获取数据,其中有必须通过GET请求进行JSONP解决方案不使用 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可确实是用来克服同源策略的限制,但也可以使用 CORS ,在现代浏览器中实现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数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-01 16:31