If you handle submitting a form using a special submit event handler, you can handle validation on the same page:
//bind an event handler to the submit event for your login form $(document).on('submit', '#form_id', function (e) { //cache the form element for use in this function var $this = $(this); //prevent the default submission of the form e.preventDefault(); //run an AJAX post request to your server-side script, $this.serialize() is the data from your form being added to the request $.post($this.attr('action'), $this.serialize(), function (responseData) { //in here you can analyze the output from your server-side script (responseData) and validate the user login without leaving the page }); });
To stop jQuery Mobile from starting your own AJAX profile of your form, put this in your form tag:
<form data-ajax="false" action="...">
source share