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