I'm having some issues submitting a form with ajax.
I built a site with youtube search functionality. I have the index page and a results page.
The results page takes a variable in the url to perform the search (results.php/?q=myyoutubesearch).
The index page has the search bar and I would like to be able to perform the search without having to reload the page and have the results display inside a div already on the page. No matter what I do though, when I click "search" the page redirects and doesn't perform the ajax request. Here is my code:
I'm curious why you think you need two different versions of that code: One for IE, one for non-IE??? jQuery-based AJAX code should work just fine in any major browsers. Yes, even IE.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
you bind your ajax request directly to the submit event by using .submit(),l then regardless if they click a submit type button or press enter your ajax request will process. ( e.preventDefault() prevents the form from submitting itself in the normal fashion so the page doesnt reload)
I just wanted to chime in to say that simply changing the button type from “submit” to “button”, as OldPedant has suggested, is not the ideal solution because you basically remove the possibility to submit the form by pressing the button if JS isn’t available for whatever reason (and don’t come with “everyone has JS enabled nowadays”, this is such a simple issue that it doesn’t require you to jump through hoops to get it right). The better solution is the one DanInMa has suggested.