Javascript для загрузки ссылки в зависимости от настроек переключения в JQuery Mobile - PullRequest
0 голосов
/ 31 января 2012

У меня есть JQM с тумблером.Когда форма будет отправлена, я бы хотел, чтобы JQM загружал страницу в зависимости от настройки переключателя.

Как мне поступить?

1 Ответ

0 голосов
/ 31 января 2012
//bind event handler to the form for the `submit` event
$('form').bind('submit', function () {

    //cache the form element for use later
    var $form = $(this);

    //show loading message
    $.mobile.showLoadingMsg();

    //create an AJAX request using the form's attributes as settings
    $.ajax({
        url     : $form.attr('action'),
        type    : $form.attr('method'),
        data    : $form.serialize(),//this serializes the form's data for transmission
        success : function (serverResponse) {

            //now hide the loading message because the AJAX call is done
            $.mobile.hideLoadingMsg();

            //and redirect the user to the specified page,
            //I am just forwarding the user to the value of the toggle
            //but you can create an if/then statement that directs the user to the proper page
            $.mobile.changePage($('#' + $form.find('.ui-slider-switch').val()));
        }
    });

    //return false to stop the default submission of the form
    return false;
});

Вам также необходимо отключить автоматическую обработку формы AJAX, это можно сделать, добавив data-ajax="false" к тегу form:

<form action="..." data-ajax="false" method="...">
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...