Home > Software design >  Do variables get set before ajax runs?
Do variables get set before ajax runs?

Time:11-11

Given the code below, is it safe to say the id passed in the ajax call below will always be 1 or is there a chance id can be null/undefined?

$('.clickTest').click(function () {
    var id = 1;
    $.ajax({
        type: 'post',
        url: "TestClick?id="   id,
        success: function (r) {
            console.log('success');
        },
        error: function (r) {
            console.log('error');                
        }
    });
});

CodePudding user response:

It's going to be 1, but you should use const instead of var.

  • Related