I am using the brilliant BlockUI, and have set it up using the default
$(document).ajaxStart($.blockUI).ajaxStop($.unblockUI);
Which is great - except when I add a autocomplete element on the page, and then the blockUI kicks in as soon as the user starts typing. Rather than explicitly set what ajax calls to launch the block UI can anyone think of a way to disable blockUI for certain ajax functions?
In jQuery an ajax call accepts different settings A set of key/value pairs that configure the Ajax request. All settings are optional.
Now here we have the following:
settings name: global,Type: Boolean, Default: true
Description: Whether to trigger global Ajax event handlers for this request. The default is true. Set to false to prevent the global handlers like ajaxStart or ajaxStop from being triggered. This can be used to control various Ajax Events.
Example:
$.ajax({
global: false,
type: "POST",
url: 'ajax/test.html',
success: function(data) {
$('.result').html(data);
alert('Load was performed.');
}
});
Above example will stop execution of any ajax start or ajax stop events like blockUI.
You could do something like this:
var dontBlock = false;
$(document).ajaxStart(function(){
if(!dontBlock)
$.blockUI();
}).ajaxStop($.unblockUI);
// And in the ajax methods (to be excluded), set dontBlock accordingly
$('#autocomplete').keydown(function(){
dontBlock = true;
$.ajax({
// url, data etc.
success: function(){ dontBlock = false; }
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With