Skip to content

How to obtain CRUD type in Ajax call after submit?

Question: 
I want to know if the event is an update, delete or insert in the ajax code. Below is my example, all works fine, but I need to know if it is insert, delete or update to do something in my PHP code.

$afterSubmit = <<<AFTERSUBMIT 
function (event, status, postData) 

//IS INSERT, UPDATE OR DELETE?

var parametros = { 
"username" : postData.username, 
"password" : postData.password, 
"email" : postData.email, 
"status" : postData.status, 
"company" : postData.company, 
"name" : postData.name, 
"type" : postData.type, 
"language" : postData.language, 
}; 

$.ajax({ 
data: parametros, 
url: 'users.php', 
type: 'post', 
success: function (response) { 
alert(response); 

}); 

AFTERSUBMIT;


Answer:
jqGrid has an event called "jqGridAddEditAfterSubmit", it's the third parameter "frmoper" return just what you need. See https://github.com/tonytomov/jqGrid/blob/master/js/grid.formedit.js#L745

The alternative approach is to make a simple change to the end of the edit.php to add to CRUD type in the JSON returned. Then in the afterSubmit event, you can parse the response object to obtain that value in your javascript code. You will need to obtain a commercial licenses to make such change.

Feedback and Knowledge Base