Capturing a form submit with jquery and .submit

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

    $(document).ready(function () {
      var form = $('#login_form')[0];
      form.onsubmit = function(e){
      var data = $("#login_form :input").serializeArray();
      console.log(data);
      $.ajax({
      url: "the url to post",
      data: data,
      processData: false,
      contentType: false,
      type: 'POST',
      success: function(data){
        alert(data);
      },
      error: function(xhrRequest, status, error) {
        alert(JSON.stringify(xhrRequest));
      }
    });
        return false;
      }
    });
    
    
    
    Capturing sumit action
    
    
    
    

提交回复
热议问题