Do while javascript issue

后端 未结 3 1425
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 06:46

I\'m trying to send multiple post within a do while loop but the result is not added



        
3条回答
  •  长发绾君心
    2021-01-16 07:19

    The Ajax request is asynchronous, which means by the time the success handler returns, the loop is already completed. Instead, you can create a closure to preserve the value:

    success: (function(i){
        return function() {
             $('div#append_result').append(i + ',
    '); } })(initval)

提交回复
热议问题