php-jqgrid编辑操作如何将变量发送到服务器?

我以为jqgrid将列名作为变量发送,当您编辑一行时,但在我创建的网格中这似乎不起作用,除非我在php的某个地方犯了错误. jqgrid用哪种方法将这些数据发送到服务器?

这是我的代码.

Index.html

<script type="text/javascript">

$(function(){ 

  var mygrid = $("#list");

  mygrid.jqGrid({
    url:'example1.php',
    editurl: 'edit.php',
    datatype: 'xml',
    mtype: 'GET',
    colNames:['Inv No','Date', 'Amount','Tax','Total','Notes'],
    colModel :[ 
      {name:'invid', 
        index:'invid', 
        width:55
      }, 
      {name:'invdate', 
        index:'invdate', 
        width:90,
        editable:true
      }, 
      {name:'amount', 
        index:'amount', 
        width:80, 
        align:'right', 
        search:true , 
        stype:'select', 
        searchoptions:{value:':All;8:8.00;6:6.00'},
        editable:true
      }, 
      {name:'tax', 
        index:'tax', 
        width:80, 
        align:'right',
        editable:true
      }, 
      {name:'total', 
        index:'total', 
        //width:80, 
        align:'right', 
        sortable:true,
        editable:true,
        editrules:{required:true},
        edittype:'select',
        editoptions:{value:"5:55.00;2:25.00"}
      }, 
      {name:'note', 
        index:'note', 
        width:150, 
        search:true , 
        align:'center', 
        editable:true, 
        editrules:{required:true, edithidden:true}, 
        hidden:true,
        edittype:'textarea',
        editoptions: {rows:"12",cols:"10"}
      }
    ],
    pager: '#pager',
    emptyrecords: "Nothing to display",
    recordtext: '{0} - {1} of {2}',
    rowNum:9,
    rowList:[7,9,11],
    viewrecords: true,
    caption: 'My first grid',
    sortname: 'invid',
    sortorder: 'desc',
    loadonce : true

  });
  //Search button
  $("#bsdata").click(function(){ mygrid.jqGrid('searchGrid', {sopt:['eq'],top:300,caption:"test searching"} ); });
  // Search toolbar.
  mygrid.jqGrid('filterToolbar', {stringResult: true, searchOnEnter: false, defaultSearch : "eq"});
  //NavBar
  mygrid.jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:true});

  // Edit Row

  $("#bedata").click(function(){ 
        var gr = mygrid.jqGrid('getGridParam','selrow'); 
        if( gr != null ) 
        mygrid.jqGrid('editGridRow',gr,{height:480,reloadAfterSubmit:false}); 
        else alert("Please Select Row");        
  });

  // Add row

  $("#badata").click(function(){ 
        mygrid.jqGrid('editGridRow',"new",{height:480,reloadAfterSubmit:false}); 
  });

  // Delete row

  $("#bddata").click(function(){ 
        var gr = mygrid.jqGrid('getGridParam','selrow');
        if( gr != null ) 
            mygrid.jqGrid('delGridRow',gr,{reloadAfterSubmit:false}); 
        else 
            alert("Please Select Row to delete!"); 
  });

}); 


</script>

和edit.php

<?php

// connect to the database
$dbhost = "localhost";
$dbuser = "user";
$dbpassword = "user123";
$database = "test";
$tablename = "invheader";
$db = mysql_connect($dbhost, $dbuser, $dbpassword)
or die("Connection Error: " . mysql_error());

mysql_select_db($database) or die("Error conecting to db.");
//mysql_set_charset('utf8',$database);
mysql_query("SET NAMES 'utf8'");


 if($_GET['oper']=='add')
 {

 }
 if($_GET['oper']=='edit')
 {
    $id     =   mysql_real_escape_string($_GET['id']);
    $date   =   mysql_real_escape_string($_GET['invdate']);
    $amount =   mysql_real_escape_string($_GET['amount']);
    $tax    =   mysql_real_escape_string($_GET['tax']);
    $total  =   mysql_real_escape_string($_GET['total']);
    $note   =   mysql_real_escape_string($_GET['note']);

    $sql = "UPDATE ".$tablename." SET invdate = '".$date."', client_id = '5' , amount = '".$amount."', tax = '".$tax."', total = '".$total."' , ";
    $sql.= "note = '".$note."'";
    $sql.= " WHERE invid = ".$id;

    echo $sql;
$result=mysql_query($sql) or die(mysql_error());

mysql_close($db);


 }
 if($_GET['oper']=='del')
 {

 }



?>

谢谢你的时间.

解决方法:

终于,我使用了Tamper数据firefox的插件,并意识到jqgrid中的数据是通过POST方法发送的,而不是GET,因为我在mtype:标签中设置了它.

因此,我将edit.php文件中的所有$_GET更改为$_POST并开始工作.

上一篇:php-允许用户在mysql中进行编辑


下一篇:【python】解决编辑器把py文件当作用例去运行