storing data picked up from php file in jquery
I have a php file that runs a simple jquery script:
var text = $(".hide").text();
I was wond开发者_Go百科ering how I could store this data when I redirect to other pages
You could put it into a cookie. Write it, leave the page, then read your own cookie when you get to the next page.
Or you could POST it to another PHP script, and store it in a session variable. In jQuery, it would look something like this
$.post("my_other_script.php", { text: "my piece of text"} );
my_other_script.php would be
<?php $_SESSION['text'] = $_POST['text']; ?>
Here is the jquery page documentation for it.
You could assign the value to a hidden form field, then either pass the value around as a form/query-string variable or save it away to a database.
$('#hidden_form_field_id').val(text);
Alternatively, if it's only a small amount of data then you could save it as a cookie.
精彩评论