Я вызываю firstpage.php, меняя значение $ _SESSION ['Progress']. Но когда я вызываю progress.php для получения значения сессии $ _SESSION ['Progress'], он сохраняет значение «1». progress.php не дает обновленного значения. Я проверил вручную firstpage.php, работая нормально. но я не знаю, почему progress.php не дает обновленного значения.Сессия не обновляется в php
var progressInterval;
$.ajax({
type: "POST",
url: "firstpage.php",
cache: false,
data: {
first: first
},
success:function(result)
{
if(progressInterval) {
clearInterval(progressInterval); //if I remove this session still show "1" output
}
alert(result); // print session value. ex:- value- 1,2,3,4,5,6,7,8,Final=8
}
});
progressInterval = setInterval(function(){
$.ajax({
url:'progress.php',
type: 'get',
data: {"name":"Progress"},
dataType:'json',
success: function(data) {
$('.output').text((parseInt(data.progress))+"%"); // KEEP SHOWING 1% (why value does not change?????)
},
error:function(err){
console.log(err);
}
});
}, 1000);
firstpage.php
session_start();
$_SESSION['Progress'] = 0;
$data=0;
$progress=$_SESSION['Progress'];
foreach($album_data as $row) //assume foreach works fine.
{
$progress++;
$_SESSION['Progress'] = $progress;
$data.=$progress.",";
session_write_close();
}
}
echo $data." final=".$_SESSION['Progress']; //output-1,2,3,4,5,6,7,8 final=8
progress.php код
session_start();
getProgress($_GET['name']);
function getProgress($filename) {
if (isset($_SESSION[$filename])) {
echo json_encode(array("progress" => $_SESSION[$filename]));
} else {
echo json_encode(array("progress" => 0));
}
}
показать нам, как вы установили сессию в 'firstpage.php' – meda