Skip to content

Instantly share code, notes, and snippets.

@Nor1m
Last active April 12, 2018 11:35
Show Gist options
  • Save Nor1m/9523e4af1ef47d3d3d5df58d207ea16b to your computer and use it in GitHub Desktop.
Save Nor1m/9523e4af1ef47d3d3d5df58d207ea16b to your computer and use it in GitHub Desktop.
//PHP
function getProgressAction(){
session_start();
echo isset($_SESSION['percent']) ? $_SESSION['percent'] : '';
exit();
}
public function getProgress($max, $progress, $text="Загрузка: "){
if(!$progress) $progress = 1;
if(!$max) $progress = 1;
$percent = round( ( $progress / $max ) * 100 );
if( $percent > 100 ) $percent = 99;
@ob_start();
session_start();
$_SESSION['percent'] = $text ."<b>". $percent ."</b>";
session_write_close();
}
//JS
function getProgress() {
$.ajax({
type: 'POST',
url: '/index/getProgress/',
success: function(data) {
progress_bar(data);
},
});
return false;
}
var myVar = setInterval(function() {
getProgress();
}, 300);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment