使用POST将数据发送到JSONP请求 [英] Send data using POST to JSONP request

查看:405
本文介绍了使用POST将数据发送到JSONP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要:

想要使用POST方法将数据发送到另一个域到JSONP。

Want to send data to another domain using POST method to JSONP.

代码:

$http.jsonp($scope.baseApiUrl+'QueryBuilder/getData?callback=JSON_CALLBACK')
.success(function(data, status, headers, config) {
$scope.success = true;
console.log(data);
}).error(function (data, status, headers, config) {
$scope.error = true;
});

工作正常。但是我有很多需要发送到服务的数据,跨域,并且它太大而无法通过查询字符串发送。所以我想把它作为JSON发送。

Its working fine. But 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. So i want to send it as JSON.

data: {
              "dbName":"test",
              "tables":["city","persons"],
              "filters":["city_id='Hyd'"]
       }

调查结果:

如何制作一个用jQuery指定contentType的jsonp POST请求?

无法使用JSONP发布数据跨域

如何使用JSONP从localhost向domain.com发送数据

使用PUT / POST / DELETE与JSONP和jQuery

每个帖子都显示它是不可能的。那么有没有其他方法可以做到这一点?

Every post shows that it is not possible.so is there any alternate way to do this ?

问题:

是否可以将数据发布到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?

任何直接的帮助都会非常值得注意。谢谢。

Any immediate help will be highly appreciable. Thanks.

推荐答案


是否可以将数据发布到JSONP?

Is it possible to post data to JSONP?

不,不是。

JSONP的工作原理是添加获取数据的< script> 元素 src (数据嵌入在JavaScript程序中)。您无法发出POST请求来加载JavaScript程序。

JSONP works by adding a <script> element that gets data from its src (the data is embedded in a JavaScript program). You can't make a POST request to load a JavaScript program.


或者所有数据都必须作为GET在查询字符串中传递请求?

Or does all data have to be passed in the querystring as a GET request?

JSONP是一个肮脏的黑客,可以绕过同源策略。

JSONP is a dirty hack to get around the Same Origin Policy.

引入CORS作为绕过同源策略的标准方法,它更加灵活。如果CORS授权,您可以使用XMLHttpRequest发出POST请求。请改用CORS。

CORS was introduced as standard way to get around the Same Origin Policy that is much, much more flexible. You can make POST requests with XMLHttpRequest if authorised by CORS. Use CORS instead.

这篇关于使用POST将数据发送到JSONP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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