jquery - PHP $_SESSION not working with Fancybox AJAX cal -
i'm having real battle here , hoping out. late last night trying every solution google offered still not had success.
my site has list on ingredients i'd add recipe.
to process is:
click "add recipe". opens fancybox iframe containing jquery ui tabbed content allows users enter measurement in grams.
from here user clicks "add" , fancybox content makes ajax call (having built data string created fine)..
the php file called ajax cast value passed int (of food id , weight) , stores in the:
$_session['recipe'][] = array('id' => $id , 'weight' => $weight);
once complete fancybox closes , div on starting page (step one) contains calorie information recipe should reload , update.
all steps seem work except 3.
whenever try vardump
session it's empty.
i've started session on each page, i.e. step 1, the fancybox page, ajax called page.
i'm @ total loss.
my ajax call @ step 3 is:
$(document).on('click', '.add-food-button', function () { var weight = $("input#grams").val(); var id = $("input#ingredientid").val(); //var sez = $("input#sez").val(); var datastring = 'g='+ weight +'&id=' + id ; //+ "&sid=" + sez; if (weight > 0) { $.ajax({ type: "post", url: "../ajax/add-ingredient-to-recipe.php?"+datastring, datatype: "html", data: datastring, success: function (msg) { frames.top.$.fancybox.close(true); frames.top.$('#calorie-table').load('./views/recipe-calorie-chart.tmp.php'); } }); }else{ $('#grams').addclass('errorinput'); $('#weight-label').addclass('errorlabel'); } });
and php file called (step 4) is:
<?php session_start(); include('../includes/config.inc.php'); if (isset($_get['weight']) && $_get['id']) { $weight = (int) $_get['weight']; $id = (int) $_get['id']; $_session['recipe'][] = array('id' => $id,'weight' => $weight); } ?>
i've read passing session id through ajax ajax call generating new session , need using 1 open. if case how do that?
any advice brilliant!
if check ajax call find passing "g" & "id" variable in query string. in php file checking "weight" && "id". condition not true , session never set. getting blank session value.
updated ajax call
$.ajax({ type: "post", url: "../ajax/add-ingredient-to-recipe.php?"+datastring, datatype: "html", success: function (msg) { frames.top.$.fancybox.close(true); frames.top.$('#calorie-table').load('./views/recipe-calorie-chart.tmp.php'); } });
updated php code
session_start(); include('../includes/config.inc.php'); if (isset($_get['g']) && $_get['id']) { $weight = (int) $_get['g']; $id = (int) $_get['id']; $_session['recipe'][] = array('id' => $id,'weight' => $weight); }
Comments
Post a Comment