Reputation: 25
I have html form with two input fileds and submit button.
When i click on submit button it goes in my javascript function...but it does not call the ajax function written in it.
Instead of calling ajax function the page gets reloaded
Upvotes: 1
Views: 573
Reputation: 76003
You not only have to use event.preventDefault()
(or return false
) in your event handler but you have to specifically disable the AJAX navigation for the form so jQuery Mobile doesn't do it's own form submission:
Here is one way using data-ajax
(recommended):
<form data-ajax="false">
You can also do this by changing a default of jQuery Mobile when the mobileinit
event fires:
<script src="jQuery-Core.js"></script>
<script>
$(document).bind("mobileinit", function(){
$.mobile.ajaxEnabled = false;
});
</script>
<script src="jQuery-Mobile.js"></script>
Notice the order of the <script>
tags. The downside to this method is that it disables AJAX navigation for all elements, not just the single form you're dealing with, that's why I recommend using the data attribute: http://jquerymobile.com/demos/1.1.0-rc.1/docs/api/globalconfig.html
Upvotes: 3
Reputation: 1150
have you disabled your form submit action using
e.preventDefaults()
can you show some of your code ?
Upvotes: 0