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
- <form action="../bin/form-process.php" method="post" class="ajax">
- <input class="input-field" type="text" autocomplete="on" name="first_name" />
- <input class="input-field" type="text" autocomplete="on" name="middle_name" />
- <input class="btn btn-apple-blue" id="form-submit" type="submit" value="Save" />
- </form>
and here is my ajax
- $('form.ajax').on('submit', function() {
-
- var that = $(this),
- url = that.attr('action'),
- type = that.attr('method'),
- data = {};
-
- that.find('[name]').each(function(index, value) {
- var that = $(this),
- name = that.attr('name'),
- value = that.val();
-
- data[name] = value;
- });
-
- $.ajax({
- url: url,
- type: type,
- data: data,
- success: function(response) {
-
- }
-
- });
-
-
- return false;
- });
Any ideas why its not working?
thanks