Angular的JSON $http请求不会像jQuery那样发送JSON

Angular JSON $http request do not send JSON like jQuery

本文关键字:JSON jQuery http 请求 Angular      更新时间:2023-09-26

我读过AngularJS的post request头是application/json

但是我想把它改成:

Content-Type=application/x-www-form-urlencoded; charset=UTF-8

我执行以下操作,但post请求仍然使用相同的application/json发送

这是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;
            });

我该如何设置请求的配置头呢?

标题需要是JSON对象。

试题:

{"headers" : { "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }}
从这里

:https://docs.angularjs.org/api/ng/service/http美元

headers - {Object} -字符串或函数的映射,这些字符串或函数返回的字符串代表要发送给服务器的HTTP头。如果函数的返回值为空,则不发送报头。