Ram Malhotra Ram Malhotra - 1 month ago 7
jQuery Question

Async:False not working

I am using

async:false
. Therefore in case of
success
function, it should wait till it gets a response from the function and should stop executing the code that follows the
success
function.

However it executes the code following it. Shouldn't
async
lock the process? Now in mycase, I am making
$('#val1loading').text('loading')
which has to keep showing loading until it gets a success from the ajax call. But it doesn't.

$("#val").change(function() {
$('#val1loading').text('loading');

if ($('#val').val() != '') {
$.ajax({
url: "Functions.php",
dataType: 'json',
data: {
async: false,
'link': $('#val').val()
},
success: function(result) {
$("#val1").val(result[0]);

},
error: function(xhr, status, error) {
$("#val1").val('');

}
});
} else {
//some code
}
$('#val1loading').text('');


});

Answer

async is deprecated.Inorder to solve your problem use $('#val1loading').text('') in all the cases.

$("#val").change(function(){
$('#val1loading').text('loading');

if($('#val').val() != '') {
    $.ajax({
            url: "ajaxFunctions.php",
            dataType: 'json',
            data: {'update': 'parser','link': $('#val').val()},
            success: function (result) {
                $('#val1loading').text('');

                $("#val1").val(result[0]);


            },
            error: function(xhr, status, error) {
                $("#val1").val('');
                $('#val1loading').text('');


}
        });
    }else
{
    //some code
}
//$('#val1loading').text('');