FCC最近提供了一个小set of API calls to access FCC data。特别是,我对Consumer Broadband Test API感兴趣。我试图通过jQuery访问这个API,但是失败了。请让我知道,如果我的代码做错了,或者这似乎是FCC的API的问题。为什么这个jQuery Ajax请求失败?
如果您访问在浏览器这个API请求时,它会返回一个XML响应就好:http://data.fcc.gov/api/speedtest/find?latitude=30.240236062827297&longitude=-97.64787337499999
所以我尝试使用各种方法在jQuery来加载此数据:
var url = "http://data.fcc.gov/api/speedtest/find?latitude=30.240236062827297&longitude=-97.64787337499999";
$.ajax({
type: "GET",
url: url,
success: function(data) {
console.log("ajax: " + data);
}
});
$.getJSON(url, function(data) {
console.log("getJSON: " + data);
});
$.get(url, function(data) {
console.log("get: " + data);
});
在在Firebug控制台中,所有三个请求都显示200(OK)状态,但响应正文为空。此外,由此产生的console.log
消息是:
ajax:
getJSON: null
get:
我在这里做错了什么?
我不认为这是有可能做跨域Ajax请求。您可能需要这样做:http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html – krx 2010-09-08 20:11:22