我有一些页面从数据库中获取信息。但是当按下页面时,字段只是空的(通常用数据库中的值填充)。那么是否可以使用 jQuery 移动版将一些数据或表单与后退按钮一起传递,以便我可以再次获取数据?
提前致谢
您可以使用
这个简洁的插件保存所有数据:
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;