troubleshooting Question

ajax with response.flush

Avatar of WMIF
WMIF asked on
5 Comments1 Solution3348 ViewsLast Modified:
i have a routine that i would like to use ajax.  what i need though is a status report from the processing code to report to the javascript as it goes through its steps.  i figured that i would have to insert a special character for javascript to find and act on.  when javascript sees that character, it would clear the innerhtml of the div tag and write the new status text minus that special character.  i havent quite gotten to here yet because im stuck on getting this text to javascript before the page is completely loaded.

ive got this asp code, which works correctly when i go to the page using "ajax_status.asp?a=go" to execute only this code:
Response.AddHeader "pragma","no-cache"

if request.QueryString("a") = "go" then
      response.Buffer = true
      response.Write("first line (" & now() & ")<br>")
      startdelay = now()
      do until datediff("s",startdelay,now()) >= 5
            ' nothing, just delay
      response.Write("after some delay, a next line(" & now() & ")<br>")
end if

the "first line" gets written immediately.  5 seconds later the "next line" gets written, just as i planned.  this doesnt work the same though once i get the javascript to access that same code.  it waits 5 seconds and gives me all the text at once.  i would like for the javascript to return the text as it sees it.

the javascript code:
<script language="JavaScript" type="text/JavaScript">
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
        ro = new XMLHttpRequest();
    return ro;
var http = createRequestObject();

function sndReq(div) {
    writediv = div'get', 'ajax_status.asp?a=go');
    http.onreadystatechange = handleResponse;
function handleResponse() {
    if(http.readyState == 4){
            commenttext = http.responseText
            document.getElementById(writediv).innerHTML = commenttext

and the html code:
<p><a href="javascript:sndReq('status')">get text</a></p>
<table width="400" border="1" cellspacing="0" cellpadding="0">
    <td><div id="status"></div></td>
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros