My need was to set different prices in the session and fetch those in my js script. I am using a jquery session plugin to set and get session, but it wasn’t getting session set by php, so I was trying to send variables using wp_localize
and set it in the js script.
Taking the clue from @Milo, I passed the values using json_encode
and set them to session at the ajax handler end.
This is what i did:–
show-event.php
file
$output = array(
'price' => $_SESSION['price'],
'price_for_two' => $_SESSION['price_for_two'],
'price_for_three' => $_SESSION['price_for_three'],
'price_for_retake' => $_SESSION['price_for_retake']
);
$this->json_encode( $output );
and in the ajax handler i did:–
// Setting the session value for the prices.
jQuery.session.set('price', data.price);
jQuery.session.set('price_for_two', data.price_for_two);
jQuery.session.set('price_for_three', data.price_for_three);
jQuery.session.set('price_for_retake', data.price_for_retake);
The above sets the session values for the different prices.
I could have also passed the array
but I did this which is fine.