I am returning a JSON value called insertStatus and I’d like to get it from the function aftersubmit which I have as it follows:
var addOptions =
{
closeOnEscape: true,
width:500,
url: 'addMember',
savekey: [true, 13],
afterSubmit : function(response, postdata)
{
alert(response.insertStatus);
},
resize : false,
closeAfterAdd: true
};
But I will just display the message "undefined".
I am trying to get the value of InsertStatus as JSON because this value will tell me if the insert of the new record was successfully saved to the Database or not. Maybe I should follow another approach if I cannot get the JSON value from here?
I used errorText before for another task and instead of returning a JSON value I returned an HTTP error status with a custom error message. Which would be the best approach? Even if the second approach was better I’d really like to know the answer of the first one. Thanks for your help.
Form editing module of jqGrid uses
completecallback ofjQuery.ajaxinstead of typicalsuccesscallback (see the source code). So the first parameter ofafterSubmitcallback (theresponseparameter) is object which will be named in jqGrid documentation asjqXHR. It’s extension ofXMLHttpRequest. So you should useresponseTextproperty to access the plain response from the server. If the server return object withinsertStatusencoded as JSON string then you have to parse JSON stringresponse.responseTextfirst and only then getinsertStatusproperty. The corresponding code ofafterSubmitcan be about the following: