当我使用ajax方法从服务器获取数据时,我得到整个php页面,而不是echo信息。为什么?
JS:
var myApp = angular.module("MyApp",[]);
myApp.config(function($httpProvider){
$httpProvider.defaults.transformRequest = function(obj){
var arrStr = [];
for(var p in obj){
arrStr.push(encodeURIComponent(p)+"="+encodeURIComponent(obj[p]));
}
return arrStr.join("&");
};
$httpProvider.defaults.headers.post = {
"Content-Type": "application/x-www-form-urlencoded"
};
});
myApp.controller("content",["$scope","$http",function($scope,$http){
var postData = {name:"Liu"};
$scope.onClick = function(){
$http.post("http://oda53d5ps.bkt.clouddn.com/post.php",postData)
.success(function(data,status,headers,config){
$scope.result = data;
console.log(data);
});
};
}]);

在我的PHP文件中,它是" $ str = $ _POST [" name"]; if($ str ==" Liu"){echo" Success!&#34 ;; } else {echo"失败!&#34 ;; }"