3

I'm trying to show the server error to the user on JqGrid

here is my code:

function addRow() {
$("#updateList").jqGrid('editGridRow', "new", {
    editData: {
        Year: function () { return $('#year option:selected').val(); }
    }
     , afterSubmit: function (response, postdata) { return [false, "fdfdfdfd", "141"]; }
    , height: 400, width: 400, reloadAfterSubmit: true
});

}

I do get the json error from Server with StatusCode 500 I just wanted to test so I put

return [false, "fdfdfdfd", "141"]

But I always see the default error message

"error Status: 'error'. Error code: 500"

This is a 'new' row adding model form. not inline editing.

Thanks for any help...

Nathan
  • 137
  • 3
  • 14

1 Answers1

3

There are misunderstanding when afterSubmit can be used. The function could be helpful if your server framework produce always successful HTTP code and you can only place the information about the error inside of the body of the successful response.

In your case the server returns status code 500. So you should use errorTextFormat instead. Try with

errorTextFormat: function (response) {
    return "ERROR: fdfdfdfd!";
}

More interesting implementation of errorTextFormat you can find for example here. I recommend you additionally to read the answer and play with the demo from the answer.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • 1
    Yes, I read [the answer](http://stackoverflow.com/a/6803206/315935) before & I got confused with the statement "It's important to know that afterSubmit will be called only if the server response contain error HTTP status code.". I'm pretty sure that was a typo ;) Anyhow, thanks for great answer. I see all JqGrid questions.. you rock. – Nathan May 03 '12 at 13:54
  • @SKCSKNathan001: Thanks! I fixed the typo from "contain" to "not contains". You are welcome! – Oleg May 03 '12 at 14:15