Question

I have some pages that get information from the database. But when pressing back on pages the fields are just empty (normal filled with values from database). So is it possible to pass some data or form along with the back button with jQuery mobile so I can fetch the data again?

Thanks in advance

Was it helpful?

Solution

You can save all of your data with this neat plugin:

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

Or you can take advantage of this JS function to send all of the data you need:

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

From there, in your controller, save the data to your session with:

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

And when your page is loading, just make a check to see if there is any session data:

$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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top