jquery datepicker不使用.serialize()发送数据来填充网格

时间:2010-09-09 20:05:50

标签: jquery jqgrid datepicker submit serialization

我有一个2输入类型=“文本”的表单,1个组合框和其他包含(组合框包含等于,之后,之前和之间的运算符+开始日期(jquery datepicker)+结束日期(jquery日期选择器)但是当我使用.serialize()将数据发送到服务器时,它的附加日期参数与url不相符。

我的方法:

$("form#transactionForm").submit(function() {
    var newUrl = "/cpsb/transactionHistory.do?method=getTransactionHistoryDetails&" +
                 $(this).serialize();

    $("#transactionHistory").jqGrid(
        "setGridParam",
        {"url": newUrl, datatype:"json"}).trigger("reloadGrid");
    return false;
});

标记:

<form class="transform" id="transactionForm" method="post" action="">
    <fieldset class="ui-widget ui-widget-content ui-corner-all">
        <legend class="ui-widget ui-widget-header ui-corner-all">Transaction History</legend>
        <p>
            <label for="lpn">LPN</label>
            <input id="lpn" name="lpn"/>
        </p>
        <p>
            <label for="sku">SKU</label>
            <input id="sku" name="sku" class="skui ui-widget-content" />
        </p>
        <p>
            <label for="ttype">Transaction Type:</label>
            <select id="ttype" name="tranType" >
            <option value="">Select transaction type</option>
            <option value="100">100-Receipt</option>
            <option value="110">110-Shipment</option>
            <option value="120">120-Pallet Update</option>
            </select>
        </p>
        <p>
            <label for="tdate">Transaction date:</label>
            <select id="tdate" name="date">
                <option value="equalsDate">Equal</option>
                <option>Between</option>
                <option value="beforeDate">Before</option>
                <option value="afterDate">After</option>
            </select>
            <input id="sdate" type="text"  style="width:70px"/>
            <input id="edate" type="text"  style="width:70px"/>
        </p>
        <p>
            <button class="submit" type="submit">Search</button>
        </p>
    </fieldset>
</form>

1 个答案:

答案 0 :(得分:6)

问题很简单。如果您希望具有"sdate""edate"且具有datepicker的输入字段将在名称startDateendDate下序列化,则必须修改HTML代码来自

<input id="sdate" type="text"  style="width:70px"/>
<input id="edate" type="text"  style="width:70px"/>

<input id="sdate" name="startDate" type="text" style="width:70px"/>
<input id="edate" name="endDate"   type="text" style="width:70px"/>

函数jQuery.serialize()仅序列化具有name属性的元素。您的<select>所有name属性都已被序列化。