2006/10/24, Miel Soeterbroek <[EMAIL PROTECTED]>:
> Barry,
>
> I've added some code to show an error message.
> Quite ugly solution though:
> I catch all returned text, and look for the following string '[error]',
> if it's found, I revert the form field text and alert the error.
>
> The trick is to format the error texts well (ie containing the search
> string). A more elegant solution would be something parameterized or
> something like JSON, but this worked for me:
>
>             /* show the saving indicator */
>             $(self).html(options.indicator);
>             $(self).load(settings.url, p, function(str) {
>                 self.editing = false;
>                     var curTxt = $(self).html();
>                     /* check for error and revert if found.
>                 if(curTxt.indexOf('[ERROR]') != -1 ) {
>                         self.innerHTML = self.revert;
>                         alert(curTxt);
>                 }
>             });
>
> Cheers,
> Miel
>

how about that:
if an error occours, let the server send a 500 header and the error
message as a content.

header("HTTP/1.1 500 Internal Server Error");
print("this cannot be done.");


to get this working you have to replace $(self).load(..) call with
$.ajax() call:

$.ajax({
               url:settings.url,
               type: "POST",
               data: $.param(p),
               complete: function(str){self.editing = false;},
               success: function(r){self.innerHTML=r;},
               error: function(r){alert("ERROR: "+ r.responseText);}
            });

error: alerts the message or does whatever you want. i contacted the
author who wants to think about that.
another solution could be to use ajaxError (i just stumbled across).
but that leads me to another question: is it possible to populate the
error response there?
-robert

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to