Angular post json data to the server, cross-origin access, multiple braces
Angular. module ('myapp', []). config (function ($ httpProvider) {$ httpProvider. defaults. useXDomain = true; delete $ httpProvider. defaults. headers. common ['x-Requested-with']; $ httpProvider. defaults. headers. post ['content-type'] = 'application/x-www-form-urlencoded; charset = UTF-8 '; $ httpProvider. defaults. headers. put ['content-type'] = 'application/x-www-form-urlencoded; charset = UTF-8 '; // Override $ http service's default transformRequest $ httpProvider. defaults. transformRequest = [function (data) {/*** The workhorse; converts an object to x-www-form-urlencoded serialization. * @ param {Object} obj * @ return {String} */var param = function (obj) {var query = ''; var name, value, fullSubName, subName, subValue, innerObj, I; for (name in obj) {value = obj [name]; if (value instanceof Array) {for (I = 0; I
Thanks, I finally found the transmission method of the json data post to the server, and won't report the cross-origin access and server receipt format errors any more. I am tired of the problem of multiple brackets, ({'{"params1": "xxxx", "params2": "cxxxxxx"}', ''}), finally solved,
To put it bluntly, convert it to application/x-www-form-urlencoded, and add &
Or the data in your post request is defined by data: {"params1": "xxxx", "params2 ": "cxxxxxx"} changed to params1 = "xxxx" ¶ ms2 = "xxxx ",
1. The following is my definition, which is mainly used for cross-origin access. It is a standard method provided by angularjs CORS.
$ HttpProvider. defaults. useXDomain = true; delete $ httpProvider. defaults. headers. common ['x-Requested-with']; $ httpProvider. defaults. headers. post ['content-type'] = 'application/x-www-form-urlencoded; charset = UTF-8 '; $ httpProvider. defaults. headers. put ['content-type'] = 'application/x-www-form-urlencoded; charset = UTF-8 ';
2.
$ HttpProvider. defaults. transformRequest is overwritten,
The json data request is converted to params1 = "xxxx" ¶ ms2 = "xxxx" format.
Zookeeper