user1217675
user1217675

Reputation: 25

How to call ajax function on submitting form through javascript in android, phonegap and jquerymobile

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

Answers (2)

Jasper
Jasper

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

Zaher
Zaher

Reputation: 1150

have you disabled your form submit action using

e.preventDefaults()

can you show some of your code ?

Upvotes: 0

Related Questions