javascript - jqGrid - Detecting backend HTTP response code on edit -


i have jqgrid have added editing functionality through php script. have seen when row edited , row data posted through ajax/jquery http request.

my php scripts takes edits, runs sql statement , fine.

nevertheless, wish check if data not insert correctly , respond non 200 response code.

i wondering how parse response code php script in order cancel row edit if server not return 200.

thus far have added callback function reloadtable edittable call, returns id of edited row.

$('#grid').jqgrid("editrow", id, true, '', '', '', '', reloadtable);  function reloadtable(result) {         //alert(result);     } 

update

based on answer jqgrid reload grid after successfull inline update / inline creation of record have tried adding following not refresh grid...

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 grid id             data : data, //insert data data object 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 pager div id             sortname : 'id', //the column according data sorted; optional             viewrecords : true, //if true, displays total number of records, etc. as: "view x 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 head

<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> 

sample json document

[{"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] 

the second parameter of reloadtable function contains result object has following objects:

readystate   responsetext status statustext 

the response code contained within status shown firebug output below: enter image description here


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -