admin管理员组文章数量:1026989
I have read about AngularJS post request header which is application/json
But I want to change it to:
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
I do the following but the post request is still sent with the same application/json
Here is the Angular:
$http.post("server.php", checkUserPostData,
{"headers" : "Content-Type=application/x-www-form-urlencoded; charset=UTF-8"})
.success(function(data, status, header, config){
if(data=='exists')
return true;
else return false;
});
How should I set the config header of the request then?
I have read about AngularJS post request header which is application/json
But I want to change it to:
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
I do the following but the post request is still sent with the same application/json
Here is the Angular:
$http.post("server.php", checkUserPostData,
{"headers" : "Content-Type=application/x-www-form-urlencoded; charset=UTF-8"})
.success(function(data, status, header, config){
if(data=='exists')
return true;
else return false;
});
How should I set the config header of the request then?
Share Improve this question edited Sep 26, 2015 at 15:50 Jonatas CD 9082 gold badges10 silver badges20 bronze badges asked May 24, 2014 at 18:56 Mostafa TalebiMostafa Talebi 9,19318 gold badges67 silver badges109 bronze badges 1- possible duplicate of AngularJS - Any way for $http.post to send request parameters instead of JSON? – Jim G. Commented Jan 27, 2015 at 21:27
1 Answer
Reset to default 4The headers need to be a JSON object.
Try:
{"headers" : { "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }}
From here: https://docs.angularjs/api/ng/service/$http
headers – {Object} – Map of strings or functions which return strings representing HTTP headers to send to the server. If the return value of a function is null, the header will not be sent.
I have read about AngularJS post request header which is application/json
But I want to change it to:
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
I do the following but the post request is still sent with the same application/json
Here is the Angular:
$http.post("server.php", checkUserPostData,
{"headers" : "Content-Type=application/x-www-form-urlencoded; charset=UTF-8"})
.success(function(data, status, header, config){
if(data=='exists')
return true;
else return false;
});
How should I set the config header of the request then?
I have read about AngularJS post request header which is application/json
But I want to change it to:
Content-Type=application/x-www-form-urlencoded; charset=UTF-8
I do the following but the post request is still sent with the same application/json
Here is the Angular:
$http.post("server.php", checkUserPostData,
{"headers" : "Content-Type=application/x-www-form-urlencoded; charset=UTF-8"})
.success(function(data, status, header, config){
if(data=='exists')
return true;
else return false;
});
How should I set the config header of the request then?
Share Improve this question edited Sep 26, 2015 at 15:50 Jonatas CD 9082 gold badges10 silver badges20 bronze badges asked May 24, 2014 at 18:56 Mostafa TalebiMostafa Talebi 9,19318 gold badges67 silver badges109 bronze badges 1- possible duplicate of AngularJS - Any way for $http.post to send request parameters instead of JSON? – Jim G. Commented Jan 27, 2015 at 21:27
1 Answer
Reset to default 4The headers need to be a JSON object.
Try:
{"headers" : { "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }}
From here: https://docs.angularjs/api/ng/service/$http
headers – {Object} – Map of strings or functions which return strings representing HTTP headers to send to the server. If the return value of a function is null, the header will not be sent.
本文标签: javascriptAngular JSON http request do not send JSON like jQueryStack Overflow
版权声明:本文标题:javascript - Angular JSON $http request do not send JSON like jQuery - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745670924a2162452.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论