First off, I know this is not "exactly" what you ordered/asked for, I started out like you, then I wanted to show some "canned" stuff for ajax calls as well as timed message in it for different messages so I came up with this: ( note for yours change errorMessage.show(); to errorMessage.fadein();)
<div class="myErrorContainer">
<div class="myErrorStatus ajaxLoading " id="myErrorStatus">
<span id="Errorstatus" class="ui-state-error-text myErrorStatusText"></span>
</div>
</div>
show a little ajax loading (if you want that) using CSS
.ajaxLoading
{
width: 100%;
background-image: url("../Images/ajax-loader.indicator.gif");
background-repeat: no-repeat;
background-position: left middle;
}
.myErrorStatus
{
text-align: center;
width: 100%;
}
.myErrorStatusText
{
color: #FF0000;
font-weight: bold;
}
/* show message for interval */
var saveMessageText = 'Saving...';
function ShowStatus(saveMessage, message, timeInMilliseconds)
{
var errorMessage = $("#Errorstatus");
if (saveMessage)
{
errorMessage.show();
var myInterval = window.setInterval(function()
{
message = message + '...';
errorMessage.text(message);
errorMessage.show();
}, 1000);
window.setTimeout(function()
{
clearInterval(myInterval);
errorMessage.hide();
}, timeInMilliseconds);
}
else
{
errorMessage.text(message);
errorMessage.show();
window.setTimeout('$("#Errorstatus").hide()', timeInMilliseconds);
};
};
then, I put in this to show on ALL ajax calls:(where a myUserName javascript variable has the users name)
/* Ajax methods */
/* show the message that data is loading on every ajax call */
var loadingMessage = 'Please wait loading data for ' + myUserName;
$(function()
{
$("#Errorstatus")
.bind("ajaxSend", function()
{
$(this).text(loadingMessage);
$(this).show();
})
.bind("ajaxComplete", function()
{
$(this).hide();
});
});
Then, you can use it like so:
ShowStatus(true, 'Update Failed with unknown Error', 4000);
NOTE: IF you don't want the ajax background indicator you can do a $('#myErrorStatus').removeClass('ajaxloading'); then replace it with $('#myErrorStatus').addClass('ajaxloading'); later.