Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Mobile - how do I submit forms to a URL and transit to another page inside the DOM?

in the jQuery mobile example. The page that will be displayed after a form is submitted is the same as where the form will be POST-ing/GET-ing to.

Is it posible to submit forms to a URL and transit to another page inside the DOM?

like image 319
tommi Avatar asked Dec 17 '25 10:12

tommi


1 Answers

You can add an event handler for the submit event for the form and submit the form manually, then manually transition to whatever page you want.

$(function () {
    $('#form_id').bind('submit', function (e) {
        e.preventDefault();
        $.post('path/to/file.php', $(this).serialize(), function (response) {
            $.mobile.changePage('#page_to_goto', {transition: 'slide'});
        });
    });
});

Some Notes:

  • You may need to turn-off AJAX handling of the form by adding data-ajax="false" to the form tag.
  • e.preventDefault() stops the form from submitting normally, a return false; at the end of the event handler should do the same thing.
  • $.post - http://api.jquery.com/jQuery.post/
  • .serialize() - http://api.jquery.com/serialize/
  • $.mobile.changePage() - http://jquerymobile.com/demos/1.0rc1/docs/api/methods.html
like image 55
Jasper Avatar answered Dec 20 '25 00:12

Jasper



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!