Capturing a form submit with jquery and .submit

后端 未结 5 1534
臣服心动
臣服心动 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:48

    Just replace the form.submit function with your own implementation:

    var form = document.getElementById('form');
    var formSubmit = form.submit; //save reference to original submit function
    
    form.onsubmit = function(e)
    {
        formHandler();
        return false;
    };
    
    var formHandler = form.submit = function()
    {
        alert('hi there');
        formSubmit(); //optionally submit the form
    };
    

提交回复
热议问题