form .serialize();返回空字符串

时间:2018-03-22 21:02:29

标签: javascript php html ajax

抱歉重复的问题。我不知道为什么它返回一个空值我检查是否有一个重复的名称,但没有。我错过了什么吗?我试图遵循一些解决方案,但它没有解决我的问题

脚本代码

$(document).on("click", "#btn_addbook", function(){
   $.ajax({
       url: "adminfunctions.php",
       method: "POST",
       data: $("#add_book_form").serialize(),
       success: function(data) {
           var getdata = data.trim();
           alert(getdata);
       },
       error: function(jqXHR, exception) {
           console.log(jqXHR);
       }
   });
}); 

Html代码

<!-- ADD BOOK MODAL -->
<div class="modal fade" id="add_book_modal" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content ">
            <div class="modal-header align-center">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title" id="defaultModalLabel">ADD BOOK</h4>
                <label class="control-label"></label>
                <span id="checkbookid"></span>
            </div>
            <form id="add_book_form" name="add_book_form">
                <div class="modal-body">
                    <div class="row clearfix">
                        <div class="col-md-3">
                            <div class="form-group form-float">
                                <div class="form-line">
                                    <label for="book_isbn" class="form-label">Book ISBN</label>
                                    <input type="text" maxlength="13" class="form-control text-center" id="book_isbn" name="book_isbn" onkeypress="return (event.charCode == 8 || event.charCode == 0) ? null : event.charCode >= 48 && event.charCode <= 57" pattern=".{0}|.{10,13}" required title="Either (10 to 13 chars)">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" id="btn_addbook" name="btn_addbook" class="btn btn-success waves-effect">
                        <strong>ADD</strong>
                    </button>
                    <button type="button" class="btn btn-danger waves-effect" data-dismiss="modal">
                        <strong>CLOSE</strong>
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--ADD BOOK MODAL-->

1 个答案:

答案 0 :(得分:0)

在你的php adminfunctions.php 中返回什么格式? 是json_encode还是什么? 尝试成功回调的console.log(数据).. 在你的ajax调用上添加选项dataType:“json”