Javascript-加载ajax后访问PHP会话变量
我得到了两个文件,一个是productlisting.php,另一个是producttree.php(这一个是ajax文件) 我在ajax文件producttree.php中得到了一个会话变量Javascript-加载ajax后访问PHP会话变量,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我得到了两个文件,一个是productlisting.php,另一个是producttree.php(这一个是ajax文件) 我在ajax文件producttree.php中得到了一个会话变量 $checktotalrecords=$_SESSION['totalnoofrecondfound']; 在运行ajax之后,我希望将上述变量值添加到main productlisting.php文件中 上述变量用于检查ajax中的记录数量,以便处理productlisting.php文件中的下一个
$checktotalrecords=$_SESSION['totalnoofrecondfound'];
在运行ajax之后,我希望将上述变量值添加到main productlisting.php文件中
上述变量用于检查ajax中的记录数量,以便处理productlisting.php文件中的下一个和上一个按钮
感谢producttree.php中的:
$checktotalrecords=$_SESSION['totalnoofrecondfound'];
//do some stuff to $checktotalrecords
$return = ["checktotalrecords"=>$checktotalrecords]; //add any other variables you want to return as well
echo json_encode($return);
在productlisting.php中:
我想你有这样的东西:
$.ajax(...);
把它改成
$.getJSON('producttree.php',{datatosend},function(json){
var checktotalrecords = json.checktotalrecords;
//update DOM elements with above value as needed
});
使用get或post代替。@ArunKillu我做到了。。。但是productlisting.php首先运行这就是为什么我会得到旧值…为了获得正确的值,我必须再次单击..我想…这应该通过javascript或jquery来完成…当您第一次运行时,获取新值并保持其可变,当您第二次调用时,只使用productlisting.php运行一次…仅产品树单击时更改(ajax)