2012-04-13 11 views
2

これは既知のトピックであり、解決策の1つは同期を呼び出すように変更することです。 非同期処理を行い、完全な関数でデータを取得する他の方法があるかどうかはまだ分かりません。 サンプル関数は、成功関数で新しいアセットオブジェクトを作成し、完全な関数でそのアセットへの参照を取得します。あなたは単にあなたがcompleteイベントで取得jQXhrオブジェクトを使用することができ競合機能でjQuery ajaxデータを取得する方法は?

 function getPresentation(item) { 
     $.ajax({ 
      type: "GET", 
      url: item.Url, 
      success: function (data) { 
       assets.push(new asset(item.Type, item.Url, data)); 
      }, 
      complete: function() { 
       /// How to get here the reference for the newly created asset object? 
       /// how to alert(asset)? 
      }, 
      error: function (req, status, error) { 
       alert('error'); 
      } 
     }); 

    } 

答えて

4

。 completeイベントの 実際の署名はそう

complete:function(jqXHR,status) 
{ 
if(status == 'success' || status=='notmodified') 
{ 
var asset = new asset(item.Type, item.Url, $.parseJSON(jqXHR.responseText)) 
} 
} 
+0

の線に沿ってuが取得している任意の特定のエラーをsomethng complete(jqXHR, textStatus) のですか? –

+0

imはJSONをサーバーからデータとして取得すると仮定します –

+0

確かにjson –

関連する問題