Send data using POST to JSONP request

坚强是说给别人听的谎言 提交于 2019-12-12 03:15:36

问题


Summary :

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

Code :

$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;
});

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'"]
       }

Findings :

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

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

Question :

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.


回答1:


Is it possible to post data to JSONP?

No, it isn't.

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.

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

Yes


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

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.



来源:https://stackoverflow.com/questions/35477537/send-data-using-post-to-jsonp-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!