Php jqgrid如何个性化错误状态';错误';。错误代码500

Php jqgrid如何个性化错误状态';错误';。错误代码500,php,jquery,mysql,jquery-ui,codeigniter,Php,Jquery,Mysql,Jquery Ui,Codeigniter,我将CodeIgniter与jquery网格一起使用。 我的数据库中有一个索引,说明某些组合无法插入。 唯一键user\u store\u index(Stores\u idStores,Users\u idUsers)。用户和存储的组合不能插入两次。 使用firebux,我可以看到错误 发生数据库错误 错误号码:1062。键“用户\存储\索引”的重复条目“1-5” 将值('1','5')插入到asignedto(Stores\u idStores,Users\u idUsers)中 在本例中,

我将CodeIgniter与jquery网格一起使用。 我的数据库中有一个索引,说明某些组合无法插入。 唯一键
user\u store\u index
Stores\u idStores
Users\u idUsers
)。用户和存储的组合不能插入两次。 使用firebux,我可以看到错误 发生数据库错误 错误号码:1062。键“用户\存储\索引”的重复条目“1-5” 将值('1','5')插入到
asignedto
Stores\u idStores
Users\u idUsers
)中

在本例中,我想向jqGrid中的用户显示以下消息:“您不能插入此组合,因为它已经存在”,但我得到的只是“错误状态:'error'。错误代码:500”。 我已经阅读了这里、这里和许多其他地方的解释,但我还没有找到解决办法

这是我的jqGrid的代码

  $(document).ready(function() {

           var grid = jQuery("#newapi_1351802691").jqGrid({
                    ajaxGridOptions : {type:"POST"},
                       jsonReader : {
                       root:"data",
                       repeatitems: false
                   },
                   loadError : function(xhr,status,error) {
                            alert(xhr.status+','+status+','+error);  //alert 500, error, My custom error
                    },
                    rowList:[10,20,30],
                    viewrecords: true
                   ,url:'http://localhost/sp/index.php/assigment/getData'
,editurl:'http://localhost/sp/index.php/assigment/setData'
,datatype:'json'
,rowNum:'12'
,width:'800'
,height:'300'
,pager: '#pnewapi_1351802691'
,caption:'Control de asignaciones'
,colModel:[
{name:'username',index:'username',label:'Usuario' ,align:'left',width:300,editable:false,edittype:'text',editrules:{required:true}  }
,{name:'StoreName',index:'StoreName',label:'Tienda' ,align:'center',width:200,editable:false,edittype:'text',editrules:{required:true}  }
,{name:'Users_idUsers',index:'Users_idUsers',label:'Usuario' ,align:'center',width:100,hidden:true,editable:true,edittype:'select',editoptions:{value:":Select;5:tienda1;6:tienda2;17:tienda3;18:tienda11",size:10},editrules:{edithidden:true,required:true,integer:true}  }
,{name:'Stores_idStores',index:'Stores_idStores',label:'Tienda' ,align:'center',width:100,hidden:true,editable:true,edittype:'select',editoptions:{value:":Select;1:EA001;3:EA003;4:EA005;5:EA006;6:EA007;7:EA008;8:EA009;9:EA010;10:EA011;11:EA012;12:EA013;13:EA015;14:EA017;15:EA018;16:EA019;17:EA020;18:EA021;19:EA022;20:EA002;21:EA000",size:10},editrules:{edithidden:true,required:true,integer:true}  }
,{name:'SurrugateTurn',index:'SurrugateTurn',label:'SurrugateTurn' ,align:'center',width:100,key:true,hidden:true,editable:true,edittype:'select',editoptions:{value:":Select;1:1;19:19",size:10},editrules:{hidden:true}  }
]               })
              jQuery("#newapi_1351802691")
            .jqGrid('navGrid',
            '#pnewapi_1351802691',
            {view:false,
             edit:'1',
             add:'1',
             del:'1',
             close:true,
             delfunc: null ,
             search:''
        },
        { recreateForm: true, 
        width : 400 ,
        beforeShowForm : function(form) {

         },
        closeAfterEdit:true }, // edit options

        {  recreateForm: true,
        width : 400,
         closeAfterAdd : true,
         beforeSubmit : function(postdata, formid) {
         var mensaje = '';
         var resultado = true;




          return[resultado,mensaje]; 
        }
        }, /*add options*/

        {mtype: 'POST'} /*delete options*/,
        {sopt: ['eq','cn','ge','le' ] ,     
        multipleSearch: false ,
        showOnLoad : false,
        overlay:false,mtype: 'POST'} /*search options*/
        ).navButtonAdd('#pnewapi_1351802691',
                { caption:'', buttonicon:'ui-icon-extlink', onClickButton:dtgOpenExportdata, position: 'last', title:'Export data', cursor: 'pointer'}
                );
;
        });

你能帮我解决这个问题吗…

你最好不要使用这种错误处理

原因:

  • 您看到的“500错误”是CI响应DB错误并返回“500内部服务器错误”http头
  • 这是核心函数,自动显示,除非编辑核心mysql库,否则无法更改

我建议每次用户尝试添加时检查记录的唯一性。如果我把db_debug设置为false,我可以处理我的错误,甚至可以得到mysql返回的错误号,但我最大的问题不是,我的问题是如何在jquery网格中显示任何错误消息。我试过使用afterSubmit事件,使用errorTextFormat,什么都没有。无论如何,谢谢你的回复。这就是你要找的吗?塞格,这似乎是我要找的,但是你知道我在哪里可以得到示例文件吗?这不是示例吗??包括jqGrid PHP库并进行一些尝试。从示例页面上,我看到它返回页眉500状态,只是文本错误。所以在客户端上它显示了这个错误。是的,这是一个例子,但我没有使用非免费类jqGrid PHP库。非常感谢您的帮助。错误是在服务器上生成的,我建议您在服务器上处理它,而不是向用户公开错误信息。你真的不想向恶意用户公开你的表名。是的,你的权限,但我不会显示我的表名。我将从mysql中获取错误号,并据此显示一些个性化消息。但问题是一样的,我没有显示任何错误消息,只是显示了错误状态“error”。错误代码500这不是你显示它的问题,如果你的服务器返回它,任何人都可以看到。好的,我会按照你的建议。在插入之前,我可以很容易地检查数据库中是否已经存在任何组合,但我的问题仍然存在。。如何在jqGrid中显示错误消息?