0

(これを読み始めたばかりの人は、この質問は解決済みです -- 下部を参照してください)

このajaxへの呼び出しで何が起こっているのかを理解しようとしています。このコードは、「バインダー」のリストを繰り返し処理し、サーバーからそれぞれをフェッチします。(現在、サーバーにはバインダーが 1 つしかありません。)

何が起こるか: Web ページを操作できるようになるまでに約 60 秒のタイムラグがありますが、バインダーが表示されません。最後にバインダーが表示されますが、その画像のサムネイルが表示されず、操作できません。

「log」への呼び出しからのコンソールへの出力は次のとおりです。

Binder:ここで検閲しなければならない正しい URL

そしてその直後、

getAllBinders: アイテムで終了

バインダーが最終的に表示された後でも、他には何も印刷されません。これは、「done」、「fail」、または「always」のいずれのメソッドもアクティブ化されていないことを示しています。バインダーが表示されていることはわかっているので、コードはクラッシュしていないはずです。(右?)

以下はコードです:

function getAllBinders() {
  
  var deferred = $.Deferred()

  _.each(binderPreviews, function(item, index) {

    console.log("Binder: "+ajaxPath+" "+item.url)

    $.ajax({
      xhrFields: {
        withCredentials: true
      },
      type: 'get',
      url: ajaxPath+item.url,
      dataType: 'json',
      contentType: "application/json",
      crossDomain: true
    })

    .done(function( data, message, jqxhr ) {

      console.log("getAllBinders Success!");

      // Store the binder record with an index
      $.extend(data, { order: index })

      // Replace null properties with empty strings
      _.each(data, function(value, prop, obj) {
        if( value == null ) obj[ prop ] = ''
      })

      App.Binder.createRecord( data ).save()

      // Check if it's the last call so we can resolve the activity
      if( index == binderPreviews.length - 1 ) {
        deferred.resolve()
        console.log( ConferenceApp.Binder.records() )
      }

      console.log("getAllBinders Index: "+index+", Total: "+binderPreviews.length);
    })

    .fail(function(xhr, status, msg) {
      console.log("getAllBinders Failure: "+status+", "+msg);
      console.log("getAllBinders Index: "+index+", Total: "+binderPreviews.length);
    })

    .always(function() {
      console.log("getAllBinders: ajax.always");
    });

    console.log("getAllBinders: Finished with item");

  })
}

実験として、不可能なタイムアウトを ajax 呼び出しに追加しました (以下を参照)。私のコンソールへの出力は次のとおりです。

Binder:ここで検閲しなければならない正しい URL

getAllBinders: アイテムで終了

getAllBinders の失敗: タイムアウト、タイムアウト

getAllBinders インデックス: 0、合計: 1

getAllBinders: ajax.always

    $.ajax({
      xhrFields: {
        withCredentials: true
      },
      type: 'get',
      url: ajaxPath+item.url,
      dataType: 'json',
      contentType: "application/json",
      crossDomain: true,
      timeout: 1 //Test -- this should be impossible
    })

編集:気にしないでください、私は問題を見つけました:/実行するとすぐに「完了」メソッドをクラッシュさせる実行時エラーがApp.Binder.createRecordメソッドにありました(しかし、それは私を混乱させたものです)

4

0 に答える 0