Home Break the for loop based on the ajax success variable
Reply: 0

Break the for loop based on the ajax success variable

user899
1#
user899 Published in May 24, 2018, 4:00 pm

For the following code, the emailCnt is 50 for first iteration, I need 25 in next iteration. What is the possible way to access the variable value outside the ajax success and break the for loop execution?

var limit = 50;
var emailCnt = limit;
for (var i = 0; i < 20; i++) {
    console.log(emailCnt);///this value is 50 instead I need 25     
    if (emailCnt < limit && i != 0) {
        break;
    }
    setTimeout(function () {
        submit_post(slNo, limit, function (output) {
            slNo = output;
            emailCnt = 25;
            $('#load_data').html('Hello');
        });
    }, 1000);
}
function submit_post(slNo, limit, handleData) {
    $.ajax({
        type: 'POST',
        async: false,
        url: url,
        data: { slNo: slNo, limit: limit },
        success: function (data) { handleData(data); }
    });
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.325146 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO