0

I have a php file that runs a simple jquery script:

var text = $(".hide").text(); 

I was wondering how I could store this data when I redirect to other pages

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

could I then store the _session variable to another variable?
and what about session_start()?
yes, definitely session_start(), which must be at the top of your script, or at least before the script has sent any headers to the browser. So try <?php session_start();$_SESSION['test']=$_POST['text'];?> to put the text into the session, then to fetch it out later, <?php session_start(); $text = $_SESSION['text']?>
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.