Capturing a form submit with jquery and .submit

后端 未结 5 1533
臣服心动
臣服心动 2020-12-02 15:23

I\'m attempting to use jQuery to capture a submit event and then send the form elements formatted as JSON to a PHP page. I\'m having issues capturing the submit though, I st

5条回答
  •  情歌与酒
    2020-12-02 15:46

    Wrap the code in document ready and prevent the default submit action:

    $(function() { //shorthand document.ready function
        $('#login_form').on('submit', function(e) { //use on if jQuery 1.7+
            e.preventDefault();  //prevent form from submitting
            var data = $("#login_form :input").serializeArray();
            console.log(data); //use the console for debugging, F12 in Chrome, not alerts
        });
    });
    

提交回复
热议问题