php - Redirecting to a page after ajax post. And then accessing values from $_SESSION: session is empty -


i'm posting 3 arrays of data php file(checkout.php) on server via jquery post.

$.post("checkout.php", {items_name : json.stringify(items_name), items_price : json.stringify(items_price), items_amount : json.stringify(items_amount)}, function(data){     console.log(data); //those 3 arrays(items_name, items_price & items_amount }); window.location.href = "checkout.php"; 

then receive data arrays in checkout.php , store them in $_session.

$items_name = json_decode($_post['items_name']); $items_price = json_decode($_post['items_price']); $items_amount = json_decode($_post['items_amount']);  session_start(); $_session['items_name'] = $items_name; $_session['items_price'] = $items_price; $_session['items_amount'] = $items_amount; 

when page redirects checkout.php after making jquery post, when try access data session, doesn't show anything.

session_start(); print_r($_session); 

where doing wrong?

the jquery post call executed asynchronously, code continues down redirect without waiting php script finish on server. add redirect success/complete callback post.

$.post("checkout.php", {items_name : json.stringify(items_name), items_price : json.stringify(items_price), items_amount : json.stringify(items_amount)}, function(data){     // whatever     window.location.href = "checkout.php"; }); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -