通过Ajax获取表单输入

时间:2014-06-03 03:06:17

标签: php jquery ajax jqgrid

我有一个jqgrid插件,我通过Ajax调用。我有index.php和getGridData.php。如何通过ajax在getGridData.php中传递表单输入并在getGridData.php中使用它?我尝试了序列化,但我无法在getGridData.php上传递或访问它。我需要它作为mysql的参数。这是我的代码。

<script language="javascript" type="text/javascript">
function jgGrid()
{
    $(document).ready(function () {
        $("#grid").jqGrid({
        url: "inc/Controller/getGridData.php"+$("#thisForm").serialize(),
        data : formData,
        datatype: "json",
        mtype: "POST",
        colNames: ["SiteID", "TerminalID", "TransactionType", "Amount", "ServiceStatus"],
        colModel: [
        { name: "SiteID"},
        { name: "TerminalID"},
        { name: "TransactionType"},
        { name: "Amount"},
        { name: "ServiceStatus"},
        ],
        pager: "#pager",
        rowNum: 10,
        rowList: [10,20],
        sortname: "SiteID",
        sortorder: "asc",
        height: 'auto',
        viewrecords: true,
        gridview: true,
        caption: ""
        });     
    });
}
</script>

getGridData.php

include('../Model/Queries.php');

$cardnumber =       $_POST['cardnumber'];
$transact_type =    $_POST['transact_type'];
$fromdate =         $_POST['fromdate'];
$todate =           $_POST['todate'];

$loyalty = new Queries();

$get_mid =  $loyalty->loyaltyConn($cardnumber);
$somedata = json_encode($loyalty->nposConn($get_mid, $transact_type, $fromdate, $todate));

echo $somedata;

1 个答案:

答案 0 :(得分:0)

您正在使用url: "url"+$("#thisForm").serialize()GET变量传递数据,但是从POST检索,因此您需要更改这些:

$cardnumber = $_POST['cardnumber'];
// ...
$todate = $_POST['todate'];

对于这样的事情:

$cardnumber = $_GET['cardnumber'];
// ...
$todate = $_GET['todate'];

将所有内容更改为GET查看examples here