0
我想从外部URL获取一些JSON。这对于dojo文档中的示例中的twitter请求可以正常工作。dojo.io.script.get中的回调函数
我想问题出现在回调函数中,因为我不确定是否需要一个以及在哪里放置它。
的JSON的样子:
{"upcoming":[]}
,这就是我怎么称呼它:
function getJSON(){
// Look up the node we'll stick the text under.
var targetNode = dojo.byId("results");
// The parameters to pass to xhrGet, the url, how to handle it, and the callbacks.
var jsonpArgs = {
url: url,
load: function(data){
console.log(data);
// Set the data from the search into the viewbox in nicely formatted JSON
targetNode.innerHTML = "<pre>" + dojo.toJson(data, true) + "</pre>";
},
error: function(error){
targetNode.innerHTML = "An unexpected error occurred: " + error;
}
};
test = dojo.io.script.get(jsonpArgs);
}
dojo.ready(getJSON);
蚂蚁是这样的输出我得到:
JSON:
{
"returnValue": true,
"timeStamp": 1332858447300,
"eventPhase": 0,
"target": null,
"defaultPrevented": false,
"srcElement": null,
"type": "load",
"cancelable": false,
"currentTarget": null,
"bubbles": false,
"cancelBubble": false
}
我参考了dojo.io.script中描述的回调函数 好吧,我认为问题是服务器关于json数据的缺少回调函数。如果我正确地理解了这些事情,我必须从服务器收到一个回叫函数,其中包含JSON数据,对吗? 如果这是正确的,我有问题的解决方案:) – knacker123 2012-03-27 19:30:10