【发布时间】:2016-05-30 09:17:27
【问题描述】:
总结:
想要使用 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
每个帖子都表明这是不可能的。那么有没有其他方法可以做到这一点?
问题:
是否可以将数据发布到 JSONP?还是所有数据都必须作为 GET 请求在查询字符串中传递?
任何直接的帮助都将是非常可观的。谢谢。
【问题讨论】:
-
另见:How do I send a cross-domain POST request via JavaScript?。这是一个基于那个问题的demo,它使用 iframe 发布 json 跨域。
标签: javascript angularjs http-post jsonp