2013-07-16 30 views
1

這是一個微不足道的問題,但我找不到答案。如何在提交表單後在jQuery Mobile中完成重置頁面

這是我使用提交我的形式,jQuery Mobile的代碼

$(document).on('click', '#submit', function() { // catch the form's submit event 
    // Send data to server through ajax call 
    // action is functionality we want to call and output - JSON is our data 
    $.ajax({ 
     url: 'includes/db/ajax_insert_completed_quests.php', 
     data: $('#form').serialize(), 
     type: 'get',     
     async: true, 
     beforeSend: function() { 
      // This callback function will trigger before data is sent 
      $.mobile.showPageLoadingMsg(true); // This will show ajax spinner 
     }, 
     complete: function() { 
      // This callback function will trigger on data sent/received complete 
      $.mobile.hidePageLoadingMsg(); // This will hide ajax spinner 
     }, 
     success: function (result) { 

     }, 
     error: function (request,error) { 
      // This callback function will trigger on unsuccessful action     
      alert('Network error has occurred please try again!'); 
     } 
    });       
    return false; // cancel original event to prevent form submitting 
}); 

所以把在成功函數什麼?我想要實現的是用戶停留在表單頁面上,但基本上刷新了頁面,就好像有人推送了F5一樣。

回答

0

嘗試使用此功能 -

function refreshPage() { 
    jQuery.mobile.changePage(window.location.href, { 
     allowSamePageTransition: true, 
     transition: 'none', 
     reloadPage: true 
    }); 
} 

有這一些其他的解決方案,我發現他們在這裏計算器 - jQuery Mobile Page refresh mechanism

Reload the Same Page Without Blinking on jQuery Mobile

你有沒有考慮手動設置你的表單值回在頁面上清空?這可能是一個更優化的解決方案。

+1

該函數無效,但使用$(#form)[0] .reset()將值重置爲空。沒有。 – MacBryce

相關問題