samedi 15 octobre 2016

If Statement AFTER Ajax Call

I've tried async: false but nothing seems to work for me.

var user = $('#element').text(),
    // user == 'KendrisX'
    ref;

$.ajax({
    type : 'get',
    async : 'false',
    url : '/memberlist?username=' + user,
    success : function(data) {
        if ( $('#link', data).html() ) ref = $('#link', data).attr('href');
        // ref == '/u1'
    }
});

if ( ref != undefined ) {
    // Code Block here
}

All I'm trying to do is to run the AJAX call and check if the variable ref has been defined yet. If it has, then I want to run a certain code block.

All of this will be executed within jQuery's $.each function so I plan to use $(this) within the if statement (which won't work in the AJAX call.

Aucun commentaire:

Enregistrer un commentaire