AJAX form - MySQL, jquery Not working.

AJAX form - MySQL, jquery Not working.

Hi,

 

I am trying to setup ajax with my form.

 

I came across a tutorial for setting this up but it didnt quite work for me so need a little help in getting it to work. This method seams quite good because I can easily add more fileds without changing my ajax too much and can also implement easily into other projects.

 

The form works fine without ajax.

 

Here is my form


  1. <form action="../bin/form-process.php" method="post" class="ajax">

  2. <input class="input-field" type="text" autocomplete="on" name="first_name" />

  3. <input class="input-field"  type="text" autocomplete="on" name="middle_name" />

  4. <input class="btn btn-apple-blue" id="form-submit" type="submit" value="Save"  />

  5. </form>


and here is my ajax


  1. $('form.ajax').on('submit', function() {
  2.  
  3.           var that = $(this),
  4.           url = that.attr('action'),
  5.           type = that.attr('method'),
  6.           data = {};
  7.  
  8.           that.find('[name]').each(function(index, value) {
  9.                     var that = $(this),
  10.                     name = that.attr('name'),
  11.                     value = that.val();
  12.  
  13.                     data[name] = value;
  14.           });
  15.  
  16.           $.ajax({
  17.                     url: url,
  18.                     type: type,
  19.                     data: data,
  20.                     success: function(response) {
  21.                             
  22.                     }
  23.  
  24.           });
  25.  


  26.  
  27.           return false;
  28. });

Any ideas why its not working?

 

thanks