我想运行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打印一些文本
发布于 2013-06-20 18:25:01
它确实在起作用: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);https://stackoverflow.com/questions/17210059
复制相似问题