Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BlockUI - Updating the Message while Block is Active

I am using BlockUI to help prevent interaction on my pages during ajax requests, with this simple command.

$(document)
    .ajaxStart($.blockUI)
    .ajaxStop($.unblockUI);

This works most of the time. But there are situations, such as during errors, where I want to update the contents to display the error messages returned from my server.

At first, my thought was that I had to just remove this global behavior and do every block on a completely manual basis; Which I would like to avoid for obvious reasons.

So is there any way to update the contents of the blocking message while it is still running? Such as in the error function call back from a jQuery $.ajax request? Like this?

$.ajax({
    // information
}).success(function (data) {
    // completed behavior
}).error(function (xhr, status, exception) {
    // update the blocked error message here with data returned
});

I thought just calling $.block again would work, but it doesn't seem to.

like image 243
Ciel Avatar asked Feb 03 '26 18:02

Ciel


1 Answers

You could try something like this

<div id="msg"></div>

$(document)
    .ajaxStart($.blockUI({ message: $('#msg') }))
    .ajaxStop($.unblockUI);
    .ajaxError(function(){$("#msg").html("error!");});
like image 179
Zach Spencer Avatar answered Feb 05 '26 08:02

Zach Spencer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!