Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I submit a form in jQuery async?

Tags:

jquery

ajax

forms

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

Another words:
How would I put my form data (assume id='bob') into the following code

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success,
  dataType: dataType
});
like image 889
Itay Moav -Malimovka Avatar asked Mar 29 '12 21:03

Itay Moav -Malimovka


Video Answer


2 Answers

This should do it:

$.ajax({   
   type: 'POST',   
   url: url,   
   data: $('#bob').serialize(),
   success: success,
   dataType: dataType 
}); 
like image 137
naspinski Avatar answered Oct 09 '22 15:10

naspinski


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
    }
  });
});
like image 28
Matthew Blancarte Avatar answered Oct 09 '22 13:10

Matthew Blancarte