How do I submit a form in jQuery async?

前端 未结 4 1691
醉话见心
醉话见心 2020-12-17 16:35

In mootools I would do something like $(\'form_id\').send({success:function(res){....}}); What is the parallel syntax in jQuery?

Another words:
How

相关标签:
4条回答
  • 2020-12-17 16:56

    This should do it:

    $.ajax({   
       type: 'POST',   
       url: url,   
       data: $('#bob').serialize(),
       success: success,
       dataType: dataType 
    }); 
    
    0 讨论(0)
  • 2020-12-17 16:56

    There is nothing that ships with jQuery that will automatically AJAXify a normal form for you.

    Option 1 -- Intercept the form's submit event, scrape the data from form fields using serialize, and send using ajax or post, as suggested.

    Option 2 -- Use this great forms plugin, which does all of option 1 for you.

    0 讨论(0)
  • 2020-12-17 17:00

    Wouldn't you know... It's right there in the documentation! :P

    http://api.jquery.com/jQuery.ajax/

    Edit: okay okay...

    $('#too_cool_form').submit(function(e){
      e.preventDefault();
      //do some verification
      $.ajax({
        url: '',
        data: $(this).serialize(),
        success: function(data)
        {
          //callback methods go right here
        }
      });
    });
    
    0 讨论(0)
  • 2020-12-17 17:21

    $.post() or $.ajax()

    $.ajax({
      type: 'POST',
      url: url,
      data: data,
      success: success,
      dataType: dataType
    });
    

    The documentation will explain it best: http://api.jquery.com/jQuery.post/

    0 讨论(0)
提交回复
热议问题