Question

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.

Was it helpful?

Solution

You could try something like this

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

$(document)
    .ajaxStart($.blockUI({ message: $('#msg') }))
    .ajaxStop($.unblockUI);
    .ajaxError(function(){$("#msg").html("error!");});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top