|
-
Jul 9th, 2008, 03:46 AM
#1
Thread Starter
Frenzied Member
Php script steps - Ajax to show steps, not just completed
Hi,
Dont really know how to explain but let me try.
At the moment I got a php script that perform several steps like:
Check if a table exist
Create table if it does not exist
Pull, scrub and insert data from another table to this new table
Loop through the table and process record by record
As it goes through the steps, it will return an error (Like "Could not create table") or continue to the next step, until all done, then return noting (So in the JavaScript I know it was successful)
I run this script via Ajax the normal way, waiting for the readyState to be 4 and the status to be 200 and then act.
Code:
function processed() {
if (request.readyState == 4) {
if (request.status == 200) {
var _indicator = document.getElementById('_indicator'); // progress bar
var _message = document.getElementById('_message');
_indicator.style.display = 'none';
_result = request.responseText;
if(_result=="") {
_message.innerHTML = "Ip2Location data processed successfully!";
} else {
_message.innerHtml = _result;
var _form = document.getElementById('_form');
_form.style.display = 'block';
}
}
}
}
All of this works fine, but I was wondering if there is a way to return a "current status" from the php script to ajax which cna then change some "Current Status is .... whatever" on the calling page?
It's not a big issue, just curious about this
-
Jul 9th, 2008, 10:39 PM
#2
Thread Starter
Frenzied Member
Re: Php script steps - Ajax to show steps, not just completed
Code:
Not very elegant..but this work...anyone can suggest how to make it more "dynamic" ?
addEvent(window, 'load',prepare_process, false);
function prepare_process() {
var frmEl = document.getElementById('cForm');
addEvent(frmEl, 'submit', step_one, false);
frmEl.onsubmit = function() { return false; }
}
function step_one() {
var _status = document.getElementById('status');
_status.innerHTML = _status.innerHTML + "<br />" + "Step One Running!";
var _data = "_step=one";
var _url = "scripts/ajax_multi_steps.php";
httpRequest("POST",_url,true,step_completed,_data);
}
function step_two() {
var _status = document.getElementById('status');
_status.innerHTML = _status.innerHTML + "<br />" + "Step Two Running!";
var _data = "_step=two";
var _url = "scripts/ajax_multi_steps.php";
httpRequest("POST",_url,true,step_completed,_data);
}
function step_three() {
var _status = document.getElementById('status');
_status.innerHTML = _status.innerHTML + "<br />" + "Step Three Running!";
var _data = "_step=three";
var _url = "scripts/ajax_multi_steps.php";
httpRequest("POST",_url,true,step_completed,_data);
}
function step_completed() {
if (request.readyState == 4) {
if (request.status == 200) {
switch( request.responseText) {
case "one":
step_two();
break;
case "two":
step_three();
break;
default:
alert("we are done!");
}
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|