我正在尝试使用免费的drop.io帐户在 drop 中获取资产列表(通过 JSON) 。
请注意,我已经查看了与此相关的其他两个问题(question1和question2),但它们都没有提供解决方案。
var dropName = escape("greganddonny");
var apiKey = "some key I'm not displaying it here...";
var version = "2.0";
var assetsListBaseURL = "http://api.drop.io/drops/greganddonny/assets.json?api_key=" + apiKey + "&version=" + version;
var resultingdata = null;
function getFileList() {
console.log("BEGIN: getFileList()");
var surl = assetsListBaseURL + '&callback=?';
$.getJSON(surl, function(data, textStatus) {
console.log("textStatus:" + textStatus);
console.log("BEGIN: Callback()");
resultingdata = data;
showResult();
console.log("END: Callback()");
});
console.log("END: getFileList()");
}
function showResult()
{
alert(resultingdata);
}
$(document).ready(function() {
console.log("BEGIN: document.ready");
$.ajaxSetup({
"error": function(XMLHttpRequest,textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
}
})
$("#search").click(function() {getFileList();});
console.log("END: document.ready");
});
单击页面上的搜索按钮时,将触发 getFileList() 函数。根据我的萤火虫控制台,调用 getFileList() 函数就好了。
JSON 请求也成功发出,因为当我在 drop.io 的站点上调用 assets.json 时,firebug 控制台的 Net 选项卡显示 200OK 状态。我还在“网络”选项卡的请求列表中收到以下返回 JSON:
[{"converted":"http:\/\/drop.io\/download\/public\/x0yfnmzdtet1vtxesqcm\/12a9ebc74c9a3e4e3b2e2b4ea3546b919a2519ff\/df43d2b0-926f-012c-26c2-fbe072d62af6\/2a0a5270-9270-012c-8fc9-fbfd417303a8\/v2\/content","type":"audio","status":"converted","title":"MikeAndAndyOnPhone2009.MP3","duration":118,"artist":"Unknown","created_at":"2009/10/03 17:29:02 +0000","filesize":1895424,"description":null,"track_title":"Unknown","hidden_url":"http:\/\/drop.io\/hidden\/sazpcf7522exzb\/asset\/bWlrZWFuZGFuZHlvbnBob25lMjAwOS1tcDM=","name":"mikeandandyonphone2009-mp3"}]
我使用JSONLint验证了上面返回的 JSON 块,它报告返回的 JSON 确实有效,您可以通过复制和粘贴上面的块来测试它。
我已经尝试了所有我知道如何尝试的方法,我什至在 $.ajaxSetup 方法中添加了一个“错误”选项,但我仍然没有成功返回一条错误消息,说明为什么我的回调函数不存在叫。
知道为什么会这样吗?你可以在这里测试我的脚本