I am using the following ajax get function to check the status of a user. Is it possible to set async: false
with this shorthand method? If not how can this be
Use jQuery.ajaxSetup({async:false});
because $.get()
is Jquery shorthand method with syntax jQuery.get( url [, data ] [, success ] [, dataType ] )
and to make changes to setting there is jQuery.get( [settings ] )
This might work for you
$.ajax({
url : "/submit/checkuser/",
type : "get",
async: false,
success : function(userStatus) {
if (userStatus == 'Disabled') { // check if user if disabled
} else if (userStatus == 'Deleted') { // check if user if deleted
} else {
};
},
error: function() {
connectionError();
}
});
The only way to make a synchronous $.get
call is to set ajaxSetup to synchronous:
jQuery.ajaxSetup({async:false});
This is considered bad form though, since it affects every ajax call made by JQuery on the page. I would suggest just biting the bullet and using the more elaborate jQuery.ajax
syntax.
See How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request? for a fuller discussion.
From above though, I use it like this
jQuery.ajaxSetup({async:false});
// my code
jQuery.ajaxSetup({async:true});
Try this.
$.get('/your/url/dot/com', { async: false }, function(data){
globalBaseURL = data;
});