Jump to content

[SOLVED] Progress Bar using PHP Session variables and retrieving with AJAX


nmullen

Recommended Posts

I'm running two scripts asynch ( I believe ) so one script can update a session variable based on how complete it is while the other checks and returns it to the javascript/AJAX. However, the problem I'm running into is when my second script checks the session variables and returns it to the AJAX all i get are null variables.

 

Here's the part where i'm setting my session variables and incrementing:

 

        session_start();

for($i=0;$i<10; $i++)
{
	$progress+= 100/($KWLength * 10);   
                //KWlength is already defined and through testing i always have it 
= to 1
	$_SESSION['progress'] = $progress;
         }
         session_destroy();

 

This is my secondary script which runs Asynch ( I THINK) with the above one

 

"getProgress.php"

 

<?php
        //Grabs the progress variable
        session_start();
        echo $_SESSION['progress'];
?>

 

Here's my javascript/Ajax which automates the progress (at the moment i'm just trying to increment a %). Once a button is clicked an interval is set which calls progressBar every 100 milliseconds.

 


function progressBar()
{
        //progxmlHttp is defined as a global
progxmlHttp = getSingleXMLHttpObject();

var url = "_includes/getProgress.php";

progxmlHttp.onreadystatechange = progressChange;
progxmlHttp.open("GET", url, true);
progxmlHttp.send(null);

if (progress >= 100)
{
	alert("Progress done!");
	clearInterval(interval);
}
}

function progressChange()
{
if (progxmlHttp.readyState == 4)
{
	progress = progxmlHttp.responseText;

	document.getElementById("ProgressPercent").innerHTML = 

(Math.round(progress*1000)/1000) + "%";
}
}

 

I've double checked all my code and I believe that this should be working.  Why am I getting null values from my session variables?  Are my AJAX functions not properly making requests to the server?

 

My javascript function are attached (as a .txt) which automate all of this  I apologize for all of the extra script in my javascript functions, I write a lot of different functions for testing purposes.

 

Thanks in advance!

 

[attachment deleted by admin]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.