Most of the time we need to submit post data in Ajax, similar to ANGULARJS and the encapsulated post.
But the post of jquery is obviously simpler and more humane than the angularjs.
The two look no different, the data submitted with Angularjs $http, on the PHP server can not be obtained through $_request/$_post.
This is because the post of the two handles the header differently ... jquery serializes the MyData as a JSON object, and angular does not.
Solution:
Modify the default handling of angular $httpprovider (the perfect solution)
Angular.module (' MyModule ', [],function($httpProvider) {//Use x-www-form-urlencoded content-type$httpProvider. defaults.headers.post[' content-type '] = ' application/x-www-form-urlencoded;charset=utf-8 '; /** * The workhorse; Converts an object to x-www-form-urlencoded serialization. * @param {Object} obj * @return {String}*/ varparam =function(obj) {varquery = ', name, value, Fullsubname, SubName, Subvalue, innerobj, I; for(Nameinchobj) {Value=Obj[name]; if(ValueinstanceofArray) { for(i=0; i<value.length; + +)i) {subvalue=Value[i]; Fullsubname= name + ' [' + i + '] '; Innerobj= {}; Innerobj[fullsubname]=Subvalue; Query+ = param (innerobj) + ' & '; } } Else if(ValueinstanceofObject) { for(SubNameinchvalue) {Subvalue=Value[subname]; Fullsubname= name + ' [' + SubName + '] '; Innerobj= {}; Innerobj[fullsubname]=Subvalue; Query+ = param (innerobj) + ' & '; } } Else if(Value!== undefined && value!==NULL) Query+ = encodeURIComponent (name) + ' = ' + encodeuricomponent (value) + ' & '; } returnQuery.length? Query.substr (0, Query.length-1): query; }; //Override $http Service ' s default transformrequest$httpProvider. defaults.transformrequest = [function(data) {returnAngular.isobject (data) && String (data)!== ' [Object File] '?param (data): data; }];});
Angular post-transfer background PHP cannot receive