I´m using CodeIgniter and JQuery Grid. I have seen the responses that you have been made here about this topic but I haven't been able to solve my problem with none of them.
The fact is that I have a jqGrid and I need to show the the dialog of insert several types of error that the database server returns.
For example, in one case I have this error:
Duplicate entry '18-2-1-2012-10-25' for key 'user_store_turn_index'
I need to get this and to show a custom message instead of the current:
error Status: 'Internal Server Error'. Error code: 500
I've tried with the aftersubmit
event. I've read the docs and seen the available examples but nothing works.
Inside my JavaScript code I have the function that deals with the after submit event for jqGrid:
afterSubmit : function(response, postdata){
test_validate
return false;
},
}
Then, I write the function that should get the responses for the after submit event:
function test_validate(response,postdata) {
alert('test');
if(response.responseText == '') {
success = true;
} else {
success = false;
}
return [success,response.responseText]
}
But nothing happens... Here is the almost complete jquery grid code
$(document).ready(function() {
var grid = jQuery("#newapi_1351189510").jqGrid({
ajaxGridOptions : {type:"POST"},
jsonReader : {
root:"data",
repeatitems: false
},
rowList:[10,20,30],
viewrecords: true
,url:'http://localhost/sp/index.php/turn_open/getData'
,editurl:'http://localhost/sp/index.php/turn_open/setData'
,datatype:'json'
,rowNum:'20'
,width:'600'
,height:'300'
,pager: '#pnewapi_1351189510'
,caption:'Apertura de caja'
,colModel:[
{name:'username',index:'username',label:'Usuario' ,align:'center',width:180,editable:false }
,{name:'TurnName',index:'TurnName',label:'Turno' ,align:'center',width:180,editable:false }
,{name:'date',index:'date',label:'Fecha' ,width:100,editable:true,edittype:'text',editrules:{required:false,date:true} ,editoptions: {size: 10, maxlengh: 10,dataInit: function(element) { $(element).datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,changeYear: true,yearRange: '1982:2022'})}},searchoptions: {size: 10, maxlengh: 10,dataInit: function(element) { $(element).datepicker({dateFormat: 'yy-mm-dd',changeMonth: true,changeYear: true,yearRange: '1982:2022'})}}}
] })
jQuery("#newapi_1351189510")
.jqGrid('navGrid',
'#pnewapi_1351189510',
{view:false,
edit:'1',
add:'1',
del:'1',
close:true,
delfunc: null
},
afterSubmit : function(response, postdata)
{ test_validate
return false;
},
},
{mtype: 'POST'} /*delete options*/,
).navButtonAdd('#pnewapi_1351189510',
{ caption:'', buttonicon:'ui-icon-extlink', onClickButton:dtgOpenExportdata, position: 'last', title:'Export data', cursor: 'pointer'}
);
;
function test_validate(response,postdata){
alert('test');
if(response.responseText == ''){
success = true;
}else{
success = false;
}
return [success,response.responseText]
}
});