editRow function has the following parameters:
jQuery("#grid_id").jqGrid('editRow',rowid, keys, oneditfunc, succesfunc, url,
extraparam, aftersavefunc,errorfunc, afterrestorefunc);
You current code use succesfunc
only. It is important, that the server return some HTTP status code which are grater or equal to 400. Then the server response will be interpret as error by jQuery.ajax and jqGrid. To display any error message or for any other action in case of error you should use errorfunc parameter of the editRow function.
One more small remark. You should use jQuery.parseJSON or JSON.parse
instead of the usage of eval
.
UPDATED: I answer here on your questions from the comment. Why it is important to use errorfunc
and not always succesfunc
? There are different reason. If you fill the box having the label sugar with the salt, it could has bitter consequences in your kitchen. Exactly the same is in case of wrong usage different callback functions of the editRow
. I can give just some examples:
- Errors can be produced by your server part not only explicitly. Your web server can throw an exception from any other your code like SQL Queries. Even if you catch all such errors, the input data sent to the server having wrong format or having other error can produce the response with the failed HTTP status and the error description. Such error response will produce your web server of the framework which you use (ASP.NET, PHP and so on).
- jQuery used by jqGrid should know which server response is successful and which is the error response. Frequently error response has another format, so there will not be parsed by jQuery.ajax (jQuery will not convert it from JSON string to the object).
- It is important for jqGrid to know whether the response was successful or not. In case of error jqGrid do one things after the response, in case of successful response another things. Different events will be called, different messages will be shown and so on.
What I wrote about the working with errors is the general rule. jqGrid defines many events in case of errors. For example loadError for the grid filling, errorTextFormat for all types of form editing, errorCell for the cell editing and errorfunc for inline editing. All the methods are based on the fact that in case of error the server response has the HTTP status code which corresponds the error (are grater or equal to 400).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…