# Solved: Ajax form submission not working.



## JiminSA (Dec 15, 2011)

I'm having problems with javascript/jQuery/Ajax stuff, yet again
This an Ajax call I wrote which doesn't work (doesn't call post.php) ...

```
<script type="text/javascript">
$(document).ready(function() {
  var form = $('#contact_form'); 
  var submit = $('#submit');  
  var alert = $('#success'); 

  form.on('submit', function(e) {
    e.preventDefault();
    $.ajax({
      url: 'post.php',
      type: 'POST', 
      dataType: 'html',
      data: form.serialize(),
      beforeSend: function() {
        alert.fadeOut();
      },
      success: function(data) {
		alert.fadeIn().delay(10000).fadeOut();
        form.trigger('reset');
      },
      error: function(e) {
        console.log(e);
      }
    });
  });
});
</script>
```
It does manage to do the form reset, success message display and fadeOut though
If you'd like to see the rest of the source it's here
Can anyone spot what I've screwed up?


----------



## Ent (Apr 11, 2009)

Are you sure that your form submission is working? The Submit button has a type image rather than type submit.


----------



## JiminSA (Dec 15, 2011)

> The Submit button has a type image rather than type submit.


Thanks, Josiah. Unfortunately it made no difference changing it to type="submit" (except to render a normal submit button). Incidentally I have a javascript alert on entry to my submit process, to indicate successful entry from Ajax.


----------



## Ent (Apr 11, 2009)

The other thing which is odd, though it could have other explanations, is that I get a 404 error if I try pointing the browser straight to http://surf4wheels.com/post.php

Also, your site seems to be intermittently crashing my firefox. (Not exactly a standard install so there are a gazillion possible reasons, but I thought you might want to know.)


----------



## JiminSA (Dec 15, 2011)

> I get a 404 error if I try pointing the browser straight to


Woops! My bad! I was doing the research on xampp and hadn't yet uploaded post.php - now done.


> Also, your site seems to be intermittently crashing my firefox.


Yes, there seems to be a major site problem with chrome (see my other thread) which may be doing naughties on FF, although I've not experienced any myself


----------



## Ent (Apr 11, 2009)

So does it work now?


----------



## JiminSA (Dec 15, 2011)

Sorry for the delay I was busy trying to get hold of Chrome version 37.0.2062.103 ...


> So does it work now?


No unfortunately not ...


----------



## Ent (Apr 11, 2009)

That's a pity. 
At this point, I'd just be sticking in alerts in the sending and success functions to report exactly what data you're sending and exactly what the server is sending back. I'm afraid I don't have much faith in your success banner at this point in time.  

As for the crashes, it wasn't slow down, it was full blown firefox closing and offering to send information to Mozilla. I think it was a firebug thing though, so while there's perhaps something non-standard about your site, it's probably not an issue for most of your users.


----------



## JiminSA (Dec 15, 2011)

> I'm afraid I don't have much faith in your success banner at this point in time.


Nah me neither But what would life be like without these challenges?


----------



## JiminSA (Dec 15, 2011)

Well, to cut a long story short, I have dropped Ajax and gone the old route with a message display ...


----------

