I would like to update session variable.
Let me introduce this in simple example. We get a div with input fields printed out by PHP script, with some values etc…
Example PHP code:
echo '
<div id="few-input-fields">
<input id="Name" size="20" value="' . $_SESSION['name'] . '" />
<br />
<input id="Lastname" size="20" value="' . $_SESSION['lastname'] . '" />
</div>
<span id="save">save</span>
</div>
';
Let’s say user edit this input field (id=Name) and type name “Mark” inside it and then press save text.
On click it should save/update session variable, without reloading page AND refresh input fields.
Is that possible? Perhaps with ajax / jquery? And most importantly how ?
Yes, just do a simple AJAX request. With jQuery it would be:
And your PHP:
Note
You need to add name-attributes to your input-fields.