将数据发布到 JsonP [英] Post data to JsonP
问题描述
是否可以将数据发布到 JsonP?还是所有数据都必须作为 GET 请求在查询字符串中传递?
Is it possible to post data to JsonP? Or does all data have to be passed in the querystring as a GET request?
我有很多数据需要发送到服务,跨域,而且数据太大,无法通过查询字符串发送
I have alot of data that I need to send to the service, cross domain, and it is too large to send via the querystring
解决这个问题有哪些选择?
What are the options for getting around this?
推荐答案
不可能对另一个域上的服务执行异步 POST
,因为同源政策.JSON-P 之所以有效,是因为您可以将 <script>
标签插入到 DOM 中,并且它们可以指向任何地方.
It is not possible to do an asynchronous POST
to a service on another domain, due to the (quite sensible) limitation of the same origin policy. JSON-P only works because you're allowed to insert <script>
tags into the DOM, and they can point anywhere.
当然,您可以将另一个域上的页面设为常规表单 POST 的操作.
You can, of course, make a page on another domain the action of a regular form POST.
编辑:有一些有趣的 hacks 如果您愿意付出大量努力插入隐藏的 并处理它们的属性.
Edit: There are some interesting hacks out there if you're willing to go to a lot of effort inserting hidden <iframe>
s and mucking about with their properties.
这篇关于将数据发布到 JsonP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!