Javascript cURL和jqueryajax之间的githubapi结果不同
我试图按语言和位置查询GitHub的搜索用户API。当我使用命令Javascript cURL和jqueryajax之间的githubapi结果不同,javascript,jquery,ajax,github,github-api,Javascript,Jquery,Ajax,Github,Github Api,我试图按语言和位置查询GitHub的搜索用户API。当我使用命令curl时https://api.github.com/search/users?q=location:denver+语言:php我收到146个结果。然而,当我尝试使用jQueryAjax时,我收到了一个错误 我的JavaScript代码: var url = "https://api.github.com/search/users"; var request = { q: "location:denver+languag
curl时https://api.github.com/search/users?q=location:denver+语言:php
我收到146个结果。然而,当我尝试使用jQueryAjax时,我收到了一个错误
我的JavaScript代码:
var url = "https://api.github.com/search/users";
var request = {
q: "location:denver+language:php",
sort: "repositories",
order: "desc"
};
var result = $.ajax({
url: url,
data: request,
dataType: 'jsonp',
type: 'GET'
})
.done(function() {
alert(JSON.stringify(result));
})
.fail(function() {
alert('failed');
});
什么alert(JSON.stringify(result))代码>提供:
{
"readyState":4,
"responseJSON":{
"meta":{
"X-RateLimit-Limit":"10",
"X-RateLimit-Remaining":"9",
"X-RateLimit-Reset":"1397393691",
"X-GitHub-Media-Type":"github.beta",
"status":422
},
"data":{
"message":"Validation Failed",
"documentation_url":"https://developer.github.com/v3/search/",
"errors":[
{
"message":"None of the search qualifiers apply to this search type.",
"resource":"Search",
"field":"q",
"code":"invalid"
}
]
}
},
"status":200,
"statusText":"success"
}
当我在q
上只使用一个限定符时,它工作正常,result.responseJSON.data
对象包含通常由cURL
提供的信息,请使用空格字符而不是加号(+)。将查询更改为:
q: "location:denver language:php",
它将按预期工作,因为jquery将把这个空格字符转换为加号