-1

最初のリクエストが完了するまでアプリケーションを待機させる必要があります。シナリオは、

if (str != "") {
  if (str.match(",")) {
        var poolSequencedStatus = $.get("Request1.do"), function(response){
             //alert("Req1")
        }
  }

  $.get("Request2.do"), function(response){
     //alert("Req2")
  }
}

文字列に文字「,」が含まれている場合、Request1 の完了後にのみ Request2 を呼び出す必要があります。

4

4 に答える 4

0

デフォルトでは、Jquery は同期モードで動作します。

$.ajax 設定の async:false の値を確認します。

それ以外の場合は、最新の jQuery で $.when() の利点を利用できます。

    // Using the $.when() method, we can create an object that behaves similarly
// to Deferred objects, but for COMBINATIONS of Deferred objects.
//
// The $.when() method creates a Deferred object that is resolved or rejected
// when all the Deferred objects passed into it are resolved or rejected.
var getPromise = function(name) {
  var dfd = $.Deferred();
  var num = Math.floor(Math.random() * 1000);
  setTimeout(function() { dfd.resolve(name + ": " + num); }, num);
  return dfd.promise();
};

var list = $("<ul/>").appendTo($("#target").empty());
var printLine = function(str) {
  $("<li class=well/>").html(str).appendTo(list);
};

// Each of these Promises will individually print when resolved.
var promiseA = getPromise("A").done(printLine);
var promiseB = getPromise("B").done(printLine);
var promiseC = getPromise("C").done(printLine);

// And this code will execute once all Promises have resolved.
$.when(promiseA, promiseB, promiseC).then(function(numA, numB, numC) {
  printLine(numA + ", " + numB + ", " + numC);
});
于 2014-05-26T05:48:07.060 に答える
0

promise を利用して、それを$.when($.get("Request1.do")).then(function(){});

http://api.jquery.com/jquery.when/

于 2014-05-26T05:45:47.023 に答える