Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do variables get set before ajax runs?

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');                
        }
    });
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading