这对我很管用
// default post header
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';
// send login data
$http({
method: 'POST',
url: 'abc.php',
data: $.param({
email: "abc@gmail.com",
password: "password"
}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function (data, status, headers, config) {
// handle success things
}).catch(function (data, status, headers, config) {
// handle error things
});这不是
$http.post('abc.php', {email: "abc@gmail.com",
password: "password"})
.then(function(res){
$scope.response = res.data;
})嗨,你能解释一下为什么第一个实现是有效的,第二个不是吗?我对短切和长切的角度方法非常困惑,谢谢提前
发布于 2017-11-01 19:18:52
从根本上说,问题在于您选择的服务器语言无法理解AngularJS的本地传输。
$http.post将以Content-Type: application/json格式传输您的数据
将标题更改为URL编码,如下所示:-
$http.post("abc.php", requestData, {
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
transformRequest: transform
}).success(function(responseData) {
//do stuff with response
}); 发布于 2017-11-01 18:41:31
第二个代码片段应该如下所示
$http.post('abc.php', {email: "abc@gmail.com",
password: "password"})
}).then(function(res){
$scope.response = res.data;
});https://stackoverflow.com/questions/47052954
复制相似问题