How to submit and validate a form via ajax

后端 未结 4 631
别那么骄傲
别那么骄傲 2021-01-14 03:40

Please I am trying to simultaneously submit and validate my form to my database through the use of Ajax, but it is not working for me. Here is my jquery

$(d         


        
4条回答
  •  日久生厌
    2021-01-14 03:57

    You forget to pass the response

    $(document).ready(function() {
        $(".button").click(function() {
    
            //check the validation like this
            if ($("#myform").valid()) {
                //Ajax to process the form
                $.ajax({
                    type: "POST",
                    url: "process.php",
                    data: {
                        firstname: $("#firstname").val()
                    },
    
                    //you forget to passs the response
                    success: function(response) {
                        $('#message').html(response);
                    }
                });
                return false;
            }
        });
    });
    

提交回复
热议问题