2013-10-16 41 views
0

我有一些從數據庫中獲取信息的頁面。 但是,當按下頁面時,這些字段只是空的(通常由數據庫中的值填充)。 那麼是否有可能通過jQuery mobile傳遞一些數據或表單以及後退按鈕,以便我可以再次獲取數據?添加數據jQuery手機後退按鈕

在此先感謝

+0

你給了他們'value'的? (輸入) – Albzi

+0

您可以在'pagebeforeshow'或'pageshow'上填寫數據。 – Omar

+0

是輸入值。他們通過控制器調用與$ _POST一起獲取值 – David

回答

0

您可以保存所有的數據與此整潔的插件:

http://sisyphus-js.herokuapp.com/

或者你也可以利用這個JS函數來發送你需要的所有數據:

window.onbeforeunload = function() 
{ 
    // here's the data you will send 
    var my_data = {name: "Smith", password: "abc123"}; 

    var xhr = new XMLHttpRequest(); 

    // open the object to the required url 
    xhr.open("POST", "flash_form/save", true); 

    // encode and send the string 
    xhr.send(JSON.stringify(my_data)); 
}; 

從那裏,在你的控制器,將數據保存到您的會話使用:

// No need to decode the JSON 
$this->session->set_userdata('form_flash_data', file_get_contents('php://input')); 

當你的頁面正在加載,只是讓看到一個檢查,如果有任何會話數據:

$form_data = $this->session->userdata('form_flash_data'); 
// check if there is any data available, if so print! 
// you can also return another json if there is nothing 
// eg: {msg: "no form data"} 
echo ($form_data === false) ? '' : $form_data;