A simple POST request
$http. Post (' do-submit.php ',myData). Success (function() { // Some code});
However, data submitted with Angularjs $http cannot be obtained through $_request/$_post on the PHP server side.
Instead, you need:
$params= Json_decode (file_get_contents(' Php://input '),true);
What's the solution?
- On the server side (PHP) via $params = Json_decode (file_get_contents (' Php://input '), true); Get parameters, small items can be, large items to a change. (Not recommended)
- Modify the default handling of angular $httpprovider: http://victorblog.com/2012/12/20/ Make-angularjs-http-service-behave-like-jquery-ajax/(This is the best way to facilitate future management)
- Add headers in $http: {' content-type ': ' application/x-www-form-urlencoded '},
Transformrequest:function (obj) {
var str = [];
For (var p in obj) {
Str.push (encodeURIComponent (p) + "=" + encodeURIComponent (Obj[p]));
}
Return Str.join ("&");
},
- Configure $httpprovider
varMYAPP = Angular.module (' app ',[]); MYAPP. config (function($httpProvider){$httpProvider. Defaults.transformrequest =function(obj) {varstr = []; for(varp in obj) {STR. push (encodeURIComponent (p) + "=" +encodeURIComponent (obj[p]));}returnStr.Join("&");}$httpProvider. Defaults.headers.post ={' Content-type ': ' application/x-www-form-urlencoded '}});
Ionic Use FAQ (eight)--php unable to get post data for $http