簡體   English   中英

jqgrid如何個性化錯誤狀態“錯誤”。 錯誤代碼500

[英]jqgrid How to personalize the error status 'error'. error code 500

我在使用帶有jQuery網格的CodeIgniter。 我的數據庫中有一個索引,指出無法插入某些組合。 唯一鍵user_store_indexStores_idStoresUsers_idUsers )。 用戶和商店的組合不能插入兩次。 使用firebux,我可以看到錯誤A發生數據庫錯誤,錯誤號:1062。鍵'user_store_index'的重復條目'1-5'插入asignedtoStores_idStoresUsers_idUsers )值('1','5')。

在這種情況下,我想在jqGrid中向用戶顯示以下消息:“您無法插入此組合,因為它已經存在”,但我得到的只是“錯誤狀態:'錯誤'。錯誤代碼:500”。 我已經閱讀了jqgrid服務器端錯誤消息/驗證處理jqgrid服務器異常錯誤消息以及許多其他消息的介紹 ,但是我無法找到解決方案。

這是我的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庫,否則無法更改它。

我建議每次用戶嘗試添加時都要檢查記錄的唯一性。 並返回某些錯誤以在jqgrid中處理它

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM