【发布时间】:2017-08-21 05:03:07
【问题描述】:
我是一个完整的 angularjs 新手,我使用 $http 发送到服务器,并且 php 文件非常基本。我可以从回显中获取 http 检索数据。但是我正在尝试使用返回来获取数据。有什么想法吗?
$scope.SendData = function () {
// use $.param jQuery function to serialize data from JSON
var data = $.param({
action: "get_clients"
});
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post('http://********.co.uk/*******/switchboard.php', data, config)
.success(function (data, status, headers, config) {
$scope.PostDataResponse = data;
console.log($scope.PostDataResponse);
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
console.log($scope.ResponseDetails);
});
};
php文件很简单,就是一个echo或者一个return。
<?php
echo "i am from the php file";
?>
<?php
return "i am from the php file";
?>
【问题讨论】: