2012-01-31 7 views

答えて

0
//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; 
}); 

また、あなたはformタグにdata-ajax="false"を追加することによってこれを行うことができ、フォームの自動AJAX処理を無効にする必要があります:

<form action="..." data-ajax="false" method="...">