0

jquery 再帰関数を実行したい。しかし、私のコードは機能しません。それを修正するために助けが必要です

function inserting(a, b){
    a = typeof a !== 'undefined' ? a : 0;
    b = typeof b !== 'undefined' ? b : 50;
    if(a < 5000){
        $.get("http://domain.com/process-query.php?start="+a+"&limit="+b,function(responseTxt,statusTxt,xhr){
            if(statusTxt=="success"){
                $("body").append(responseTxt);
                a = a + b;
                inserting(a,b);
            }
            if(statusTxt=="error")
                alert("Error: "+xhr.status+": "+xhr.statusText);
        });
    }
}
$(document).ready(function(){
    inserting(100, 50);
});

ご協力いただきありがとうございます

参考: process-query.php は、パラメーター a および b に基づいてテキストを出力します。

4

1 に答える 1

0

それは実際に働いています: http://jsfiddle.net/balintbako/4ZFDU/

少し簡略化されたバージョンなので、「再帰」またはajaxにあるものは何でも見ることができます:)

function inserting(a){
    if (a < 5){
        $.get("/echo/jsonp", function(responseTxt,statusTxt,xhr){
            if(statusTxt == "success"){                
                $("div").append("<p>"+ a + "<p>");
                a = a + 1;
                inserting(a);                
            }
            if(statusTxt == "error")
                alert("Error: "+xhr.status+": "+xhr.statusText);
        });
    }
}
inserting(3);
于 2013-06-20T10:25:01.133 に答える