使用 POST 向 JSONP 请求发送数据

Send data using POST to JSONP request

总结:

想使用 POST 方法将数据发送到另一个域 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.

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

调查结果:

How to make a jsonp POST request that specifies contentType with jQuery?
Unable to post data using JSONP on Cross Domain
How to send data using JSONP from localhost to domain.com
Using PUT/POST/DELETE with JSONP and jQuery

每个 post 都表明它不是 possible.so 有没有其他方法可以做到这一点?

问题:

是否可以post数据到JSONP?还是所有数据都必须作为 GET 请求在查询字符串中传递?

我们将不胜感激任何直接的帮助。谢谢。

Is it possible to post data to JSONP?

不,不是。

JSONP 通过添加一个 <script> 元素来工作,该元素 从其 src 中获取 数据(数据嵌入在 JavaScript 程序中) .您不能发出 POST 请求来加载 JavaScript 程序。

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


JSONP 是绕过同源策略的肮脏黑客。

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