Pointers or suggestions

B

Bill H

I am new to this newsgroup, so if I step on any established
conventions or rules, please bear with me.

I am attempting to use AJAX as a way of informing a visitor that
things are happening so they dont hit their back button, or click
submit again etc. What I want to be able to do is give them a running
status. Something like this:

Saving your data.... done
Updating your profile... done
Creating your pdf... done
Operation complete.

Where the "done" shows up when a particular event has happened on the
server. I have already created the perl routines that send a simple
"ID|STATUS" as it goes along but the problem is it doesnt show
anything till it is all done. Here is a simple html program I am using
to test it.

<HEAD>
</HEAD>
<BODY>
Hello <a href="javascript:sndReq('foo')">click me</a></P>
<script language="javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sndReq(action) {
http.open('get', 'project.pl?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
document.HERE.THIS.value += response;
}
}
</script>
<P>
<FORM NAME="HERE">
<TEXTAREA NAME="THIS" COLS="60" ROWS="6"></TEXTAREA>
</FORM>
</body>
</html>


The program project.pl right now is sending a new status every 2
seconds for this test purpose (and it is doing every 2 seconds when I
test the program directly in the browser).

I hope I am making sense with this.

Bill H
 
M

Martin Honnen

Bill said:
The program project.pl right now is sending a new status every 2
seconds for this test purpose (and it is doing every 2 seconds when I
test the program directly in the browser).

The script code you have posted does one HTTP request and on readyState
being 4 it processes the complete response. You might want to try to
access responseText on readyState being 3 if you expect the response to
consist of several items. But I am not sure how well that works with the
different implementations of XMLHttpRequest respectively XMLHTTP.
 
B

Bart Van der Donck

Bill said:
I am attempting to use AJAX as a way of informing a visitor that
things are happening so they dont hit their back button, or click
submit again etc. What I want to be able to do is give them a running
status. Something like this:

Saving your data.... done
Updating your profile... done
Creating your pdf... done
Operation complete.

Where the "done" shows up when a particular event has happened on the
server. I have already created the perl routines that send a simple
"ID|STATUS" as it goes along but the problem is it doesnt show
anything till it is all done.
[...]

You can unbuffer output in Perl with $OUTPUT_AUTOFLUSH ($|) so that it
shows what is ready:

#!/usr/bin/perl
$|++;
print "Content-Type: text/html\n\n";
print q{Waiting 2 seconds...};
sleep 2;
print q{OK};
print q{<br>Waiting 6 seconds...};
sleep 6;
print q{OK};

Hope this helps,
 
B

Bill H

Bill said:
I am attempting to use AJAX as a way of informing a visitor that
things are happening so they dont hit their back button, or click
submit again etc. What I want to be able to do is give them a running
status. Something like this:
Saving your data.... done
Updating your profile... done
Creating your pdf... done
Operation complete.
Where the "done" shows up when a particular event has happened on the
server. I have already created the perl routines that send a simple
"ID|STATUS" as it goes along but the problem is it doesnt show
anything till it is all done.
[...]

You can unbuffer output in Perl with $OUTPUT_AUTOFLUSH ($|) so that it
shows what is ready:

#!/usr/bin/perl
$|++;
print "Content-Type: text/html\n\n";
print q{Waiting 2 seconds...};
sleep 2;
print q{OK};
print q{<br>Waiting 6 seconds...};
sleep 6;
print q{OK};

Hope this helps,

Bart - thanks. I figured out that part out.

Bill H
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top