一、代码如下:
$http({ method:'post', url:'post.php', data:{name:"aaa",id:1,age:20} }).success(function(req){ console.log(req); })解决方案:
1、
var myApp = angular.module('app',[]);myApp.config(function($httpProvider){ $httpProvider.defaults.transformRequest = function(obj){var str = [];for(var p in obj){str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));}return str.join("&");2.
$http({method:'post',url:'post.php',data:{name:"aaa",id:1,age:20},headers:{'Content-Type': 'application/x-/appapi.php?a=getPortalList&catid=20&page=1&callback=JSON_CALLBACK"; $http.jsonp(myUrl).success( function(data){ console.log(data); } ).error(function(err){ //错误代码 }); $scope.firstName="Wang"; $scope.lastName="Ben"; });</script></body></html><?php//postData.php文件//用接收json数据的方式$msg=file_get_contents("php://input",true);$name=$_GET['name'];echo $name.$msg."_post";显示效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。