re1man
re1man

Reputation: 2367

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 wondering how I could store this data when I redirect to other pages

Upvotes: 0

Views: 99

Answers (2)

charliefortune
charliefortune

Reputation: 3200

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.

Upvotes: 1

ipr101
ipr101

Reputation: 24236

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.

Upvotes: 0

Related Questions