I need to create progressbar for long running PHP script so I decided to write script progress to json file and then read it by Javascript. Everything works fine in Firefox but if i change browser to Chrome it stops working. No errors in Console window. The Chrome simply stops loading json file when user starts PHP script but it does read this file before PHP execution start. Is it a problem with my code or normal behaviour of Chrome browser?
PHP:
$fp = fopen($this->writeFile, "w");
fwrite($fp, json_encode($values));
fclose($fp);
//for safety we will make a copy and let client access the copy.
copy($this->writeFile, $this->readFile);
Javascript:
getProgress();
function getProgress() {
$.ajaxSetup({ cache: false });
$.getJSON("../../../../upload/status.json", function(data) {
var pbvalue = 0;
if(data){
var total = data['total'];
var current = data['current'];
if(total != 0)
pbvalue = Math.floor((current / total) * 100);
$(".progress-bar .indicator").width(pbvalue+"%");
$(".progress-text").text(current+"/"+total);
}
if(pbvalue < 99)
setTimeout("getProgress()", 3000);
});
}
JSON file:
{"total":"0","current":"0"}
EDIT 1: Thanks for timeout hint but it is working (good) in Firefox the problem is no "XHR finished loading" response inside Chrome console AFTER i start PHP execution (before it loads the file every 3 second as it is supposed to do)
EDIT 2: Probably the reason of this problem is that I try to read this JSON file AFTER user submits form. I guess that for some reasons Chrome after form submission no longer allow to execute jQuery $getJSON function. Any workarounds will be appreciated.