当我尝试从网址获取信息时,我收到了400错误的请求错误。这是我的代码:
<script src="http://code.jquery.com/jquery-3.1.1.js"></script>
function searchData()
{
dname = document.getElementById('dataname').value;
$.ajax({
type: "GET",
url: "http://demo.ckan.org/api/3/action/package_search?q=" + dname,
dataType: "jsonp",
contentType:"application/json",
headers: { "Authorization": "123456789123456" },
error:function(e){
console.log(e);
},
success: function (data) {
var name = "<ul id='list'>";
if (data.length !== 0) {
for (var j = 0; j < data.length; j++) {
name += "<li>"+(j+1)+":"+ data[j] +">" ;
}
}
else {
name = "Sorry, there is no data";
}
name += "</ul><hr>";
$('#result').append(name);
}
});
return false;
}
我通过谷歌浏览器尝试http://demo.ckan.org/api/3/action/package_search?q=air,它给了我很好的结果,所以这不是网址的问题。
任何人都有一些想法? 非常感谢。
答案 0 :(得分:1)
实际上问题是CKAN api不支持以jquery的方式禁用缓存。所以我必须设置cache:true
感谢Brian的想法=&gt; AJAX call error - status of 400 (Bad Request)