Javascript 400从ajax转换为$http时出错?

Javascript 400从ajax转换为$http时出错?,javascript,jquery,ajax,angularjs,Javascript,Jquery,Ajax,Angularjs,我正在尝试使用$http而不是ajax来完成GET请求。这个调用在ajax中工作得非常好,但是当我尝试使用$http做同样的事情时,我得到了一个400(错误请求)错误。我相信我正确地遵循了角度文档。有什么想法吗?希望这对其他遇到同样问题的人也有帮助 工作正常的ajax代码: $.ajax({ type: "GET", accept: 'application/json', url: myURL, headers: {"Authorization": "Basic

我正在尝试使用$http而不是ajax来完成GET请求。这个调用在ajax中工作得非常好,但是当我尝试使用$http做同样的事情时,我得到了一个400(错误请求)错误。我相信我正确地遵循了角度文档。有什么想法吗?希望这对其他遇到同样问题的人也有帮助

工作正常的ajax代码:

$.ajax({
    type: "GET",
    accept: 'application/json',
    url: myURL,
    headers: {"Authorization": "Basic " + basicKey},
    dataType: "json",
    contentType: 'application/x-www-form-urlencoded',
    data: requestPayload,
    async: false
}).done(function(serverData) {
    console.log(serverData.access_token);
}).fail(function(error) {
    console.log(error);
});
不起作用的$http代码:

var basicConfig = {
    method: 'GET',
    url: myURL,
    headers: {
        'Authorization': 'Basic ' + basicKey, 
        'Accept': "application/json", 
        'Content-Type': 'application/x-www-form-urlencoded' 
    },
    data: requestPayload 
}

$http(basicConfig).success(function(data, status){
    console.log(status);
}).error(function(data, status){
    console.log(status);
});

提前感谢。

使用
参数
而不是
数据
data
是请求主体,用于POST请求,而
params
用于GET请求中的查询字符串变量。

您没有在
$http
请求中设置数据类型?@GeraldVersluis I认为您在使用$http()时不需要数据类型使用
参数
而不是
数据
data
是请求主体,用于POST请求,而
params
是查询字符串变量。@BrianGlaz!这很有效。非常感谢。