How to get the variable for count in test.php using ajax/jquery?
The variable that i want to get is that $countses. its responsible to hold a value of count for borrow session.
//session_destroy();
if(isset($_SESSION['sBorrow'])){
$countses = count($_SESSION['sBorrow']);
echo $countses;
}
// nothing requested, so return all values
print json_encode($_SESSION);
I want to call in this place
var sessionvar;
$.ajaxSetup({cache: false})
$.get('test.php' ,function (data) {
sessionvar = data;
//var ses = sessionvar.length
//alert(ses);
/*
var count = 0;
for(var i = 0; i < sessionvar.length; ++i){
if(sessionvar[i] == 2)
count++;
alert(count);
}*/
var checkedCbs = $('.sBorrow:checked ');
if (checkedCbs.length === 2) {
alert("You can only select 3 books");
this.checked = false;
}
});
I want to call the variable for $countses so that it can be used for conditional statement. However i only get the session variable. So i comment it for a bit while finding the solution.
json_encode($_SESSION)?$_SESSION['sBorrow']? does it hold a array?you shouldn't use echo before json encode.it makes your json invalid.you may need to add count also to json object and return it