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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.