2013-08-07 29 views
1

我有一个jqGrid,我已经通过PHP脚本添加了编辑功能。 我已经看到,当一行被编辑和行数据通过ajax/jquery http请求发布。jqGrid - 编辑后检测后端HTTP响应代码

我的PHP脚本需要编辑,运行SQL语句,一切正常。不过,我希望检查数据是否没有正确插入,并用非200响应代码进行响应。

我想知道如何从PHP脚本解析响应代码,以消除该行的编辑,如果服务器没有返回200

到目前为止,我已经加入了回调函数reloadTable到editTable电话,但是这只返回编辑行的ID。

$('#grid').jqGrid("editRow", id, true, '', '', '', '', reloadTable); 

function reloadTable(result) { 
     //alert(result); 
    } 

更新

基于从jqgrid reload grid after successfull inline update/inline creation of record答案我曾尝试加入以下但不刷新格...

function reloadTable(rowid, result) { 
    $("#grid").trigger("reloadGrid"); 
} 

的Javascript:

<script language="javascript"> 

function typeSelect() { 
    return "['a','b','c']"; 
} 

function getCharacteristics() { 

    $.getJSON('json/getCharacteristics.php?category_id=3', function (data) { 
     $("#grid").jqGrid("GridUnload"); 
     data.length = data.length - 1; 

     $("#grid").jqGrid({ //set your grid id 
      data : data, //insert data from the data object we created above 
      datatype : 'local', 
      width : 500, //specify width; optional 
      colNames : ['character_id', 'gr_name', 'en_name', 'charType'], //define column names 
      colModel : [{ 
        name : 'character_id', 
        editable : true, 
        index : 'character_id', 
        key : true, 
        width : 50 
       }, { 
        name : 'gr_name', 
        editable : true, 
        index : 'gr_name', 
        width : 100, 
        editable : true 
       }, { 
        name : 'en_name', 
        editable : true, 
        index : 'en_name', 
        width : 100, 
        editable : true 
       }, { 
        name : 'charType', 
        editable : true, 
        index : 'charType', 
        width : 100, 
        editable : true, 
        edittype : "select", 
        editrules : { 
         required : true 
        }, 
        editoptions : { 
         size : 5 
        } 
       }, 
      ], //define column models 
      pager : '#pager', //set your pager div id 
      sortname : 'id', //the column according to which data is to be sorted; optional 
      viewrecords : true, //if true, displays the total number of records, etc. as: "View X to Y out of Z” optional 
      sortorder : "asc", //sort order; optional 
      editurl : 'json/getCharacteristics.php', 
      cellsubmit : 'json/getCharacteristics.php', 
      gridview : true, 
      caption : "jqGrid Example", //title of grid 
      onSelectRow : function (id) { 
       console.log('onSelectRow'); 
       editRow(id); 
      }, 
      loadComplete : function() { 
       $('#grid').setColProp('charType', { 
        editoptions : { 
         value : ['input', 'ListOptionYesNo', 'select'] 
        } 
       }); 
      } 
     }); 

    }); 
} 

var lastSelection = -1; 
function editRow(id) { 

    console.log("editRow"); 
    if (id && id !== lastSelection) { 
     console.log("setRowToEdit"); 
     var grid = $("#grid"); 
     grid.restoreRow(lastSelection); 
     console.log("id " + id); 
     $('#grid').jqGrid("editRow", id, true, '', '', '', '', reloadTable); 
     lastSelection = id; 
    } 
} 

function reloadTable(result) { 
    //alert(result); 
} 

</script> 

HTML报头

<html> 

<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 
<style> 
div.scrollCategories{ 
    height:200px; 
    overflow-y: scroll; 
    overflow-x: hidden; 
} 

td th 
{ 
font-size:10px; 
border:1px solid #98bf21; 
padding:10px 10px 10px 7px; 
} 
th 
{ 
font-size:11px; 
text-align:left; 
padding-top:5px; 
padding-bottom:4px; 
background-color:#A7C942; 
color:#fff; 
} 
tr.alt td 
{ 
color:#000; 
background-color:#EAF2D3; 
} 

#overlay_form{ 
position: absolute; 
border: 5px solid gray; 
padding: 10px; 
background: white; 
width: 270px; 
height: 190px; 
} 
#pop{ 
display: block; 
border: 1px solid gray; 
width: 65px; 
text-align: center; 
padding: 6px; 
border-radius: 5px; 
text-decoration: none; 
margin: 0 auto; 
} 
</style> 

<link href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" rel="stylesheet" media="screen" type="text/css" /> 
<link href="jquery.jqGrid-4.5.2/css/ui.jqgrid.css" rel="stylesheet" media="screen" type="text/css" /> 
<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script> 
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js" type="text/javascript"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script> 
<script type="text/javascript" src="jquery.jqGrid-4.5.2/js/i18n/grid.locale-en.js" type="text/javascript"></script> 
<script type="text/javascript" src="jquery.jqGrid-4.5.2/js/jquery.jqGrid.src.js"></script> 

</head> 

<body> 

<h3> Edit Category Characteristics</h3><hr/> 
<a name="test"/> 
<table id="grid"></table> 
<div id="pager"></div> 

</body> 

</html> 

样品JSON文献

[{"character_id":"477","en_name":"Menios","charType":"0","gr_name":"????2","categories_id":"27"},{"character_id":"479","en_name":"Nikos","charType":"1","gr_name":"bb","categories_id":"27"},false] 

回答

0

的reloadTable函数的第二个参数中包含具有以下对象结果对象:

readyState 
responseText 
status 
statusText 

响应代码被包含在状态中,如从萤火虫o中所示输出如下: enter image description here