2012-03-27 17 views
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); 

私が手出力のAnt:

JSON: 
{ 
    "returnValue": true, 
    "timeStamp": 1332858447300, 
    "eventPhase": 0, 
    "target": null, 
    "defaultPrevented": false, 
    "srcElement": null, 
    "type": "load", 
    "cancelable": false, 
    "currentTarget": null, 
    "bubbles": false, 
    "cancelBubble": false 
} 

答えて

0

この文を参照していますあなたの例では?

// The parameters to pass to xhrGet, the url, how to handle it, and the callbacks. 

もしそうなら、「コールバック」はロードとエラーの機能です。

+0

私はdojo.io.scriptに記載されているコールバック関数を参照しています。 よく、この問題は、jsonデータに関するサーバーのコールバック関数が欠落していると思います。私がそのことを正しく理解していれば、JSONデータを「インクルード」しているサーバーからコールバック関数を受け取る必要があります。 これが正しい場合、私は問題の解決方法を持っています:) – knacker123