Modal form Submission to PHP using Jquery .ajax

后端 未结 1 352
挽巷
挽巷 2021-01-21 01:09

I am trying to post a modal form to a table using php, jquery .ajax but it never works.. tried debugging using firebug and i don\'t see any errors. i tested the form by using fo

相关标签:
1条回答
  • 2021-01-21 01:49

    You should really be using .submit() rather than click (for submit-by-enter, etc.) and returning false to block conventional submits. You also need to make sure the code to bind the events runs after the form element is created. The easiest way to do this is to put it in the document ready handler.

    jQuery(document).ready(function ($) {
        $("#notesmodal").submit(function () {
            $.ajax({
                type: "POST",
                url: "notes_functions.php",
                data: $('form.noteform').serialize(),
                success: function (msg) {
                    $("#thanks").html(msg)
                    $("form.noteform").modal('hide');
                },
                error: function () {
                    alert("failure");
                }
            });
            return false;
        });
    });
    

    And change the ADD button to be:

    <input type="submit" name="submit" class="btn btn-default" id="submitnote" value="ADD" />
    
    0 讨论(0)
提交回复
热议问题