JQuery Serialize返回空数组

时间:2016-06-05 12:54:56

标签: jquery ajax serialization

我已经坚持了好几个小时,还没有能够找到任何解决方案! 我已经阅读了类似问题的解决方案,但没有解决我的问题! 任何帮助将非常感激!!! PS我确保我的选择框有名字,但没有禁用!!

$('.filter-expense').change(function(){
    console.log('working');
    var dataval = $('#filter-form-expense').serialize();
    console.log(dataval);
    $.ajax({
        type: 'POST',
        data: $('#filter-form-expense').serialize(),
        url: 'get-filter-details-expense',
        success: function(data) {
            $('#filter_expense').html(data);
        }
    });
});
<form id="filter-form-expense">
    <div class="row">
        <div class="col-md-3">
            <div class="form-group has-feedback">
                <label>Project</label>
                <span class="form-control-feedback">
                    <i class="fa fa-caret-down"></i>
                </span>
                <select class="filter-expense form-control" name="AurigahrmExpenseExpenses2[project]">
                    <option disabled selected value> -- Select an Option -- </option>
                    <?php  foreach($dataProjects as $i=>$val1){
                        echo "<option value=".$i.">$val1</option>";
                    }?>
                </select>
            </div>
        </div>
        <div class="col-md-3">
            <div class="form-group has-feedback">
                <label>Approver Name</label>
                <span class="form-control-feedback">
                    <i class="fa fa-caret-down"></i>
                </span>
                <select class="filter-expense form-control" name="AurigahrmExpenseExpenses2[approver]">
                    <?php foreach($dataApprovers as $i=>$val1){
                        echo "<option value=".$i.">$val1</option>";
                    }?> 
                </select>
            </div>
        </div>
        <div class="col-md-3">
            <div class="form-group has-feedback">
                <label>Superior Person</label>
                <span class="form-control-feedback">
                    <i class="fa fa-caret-down"></i>
                </span>
                <select class="filter-expense form-control" name="AurigahrmExpenseExpenses2[status]">
                    <option value="1">DC Comics</option>
                    <option value="2">MarvelsL</option>
                    <option value="3">Comp. Off</option>
                </select>
            </div>
        </div>
        <div class="col-md-3">
            <button type="button" name="button" class="button-type2 show-application" id="apply-leave">
                <i class="fa fa-plus pull-left"></i>
                <span class="button-text">
                    <i>Add Expense</i>
                </span>
            </button>
        </div>
    </div>
</form>

1 个答案:

答案 0 :(得分:0)

尝试使用serializeArray()代替

var dataval = $('#filter-form-expense').serializeArray();
$.ajax({
    type: 'POST',
    data: dataval,
    url: 'get-filter-details-expense',
    success: function(data) {
        $('#filter_expense').html(data);
    }
});