canadatom 0 Newbie Poster

Here is my javascript code:

var xmlhttp; 
var result; 
function load() 
{ 
 xmlhttp=null; 
 if (window.XMLHttpRequest) 
   {// code for IE7+, Firefox, Chrome, Opera, Safari 
   xmlhttp=new XMLHttpRequest(); 
   } 
 else 
   {// code for IE6, IE5 
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
   } 
 xmlhttp.onreadystatechange=state_Change; 
 xmlhttp.open("GET",getLauncherPath,true); 
 xmlhttp.send(null); 
} 
 
function state_Change() 
{ 
 if (xmlhttp.readyState==3){ 
  if (xmlhttp.status==200){ 
   result = "readyState = 3, counting begins\n"; 
   result += xmlhttp.responseText; 
   document.getElementById('T1').innerHTML= result; 
  } 
 } 
 
 if (xmlhttp.readyState==4){ 
  // 4 = "loaded" 
  if (xmlhttp.status==200) 
  {// 200 = "OK" 
   document.getElementById('T1').innerHTML= result + "\nreadyState = 4, DONE"; 
  } 
 } 
}

Here is my perl code

#!C:/perl/bin/perl.exe 
 
use strict;  
use warnings;  
use CGI;  
 
$|++;  
 
my $cgi = CGI->new;  
 
print $cgi->header,  
      $cgi->start_html("Output Flush Buffer Test");  
 
for ( 1..3 ) {  
    print $cgi->p("Line $_");  
    sleep 1;  
}  
 
print $cgi->end_html;

Result shows in IE7

undefined readyState = 4, DONE

Result shows in Firefox

readyState = 3, counting begins 
 
Line 1 
 
Line 2 
 
Line 3 
readyState = 4, DONE

I got some advice that IE7 doesn't support MIME, that is the reason why IE7 can't flush the output by using state change, is this true? If I run this perl script directly from my IE7 browser, e.g. localhost/cgi-bin/count.pl, IE7 actully shows results line by line with time delay. It is just not working with AJAX.

There is alternative way to flush the output in IE7 which I hate to do
1. stdout output into a log file in perl
2. When ajax starts call count, there will be another javascript to call the log file and print the text on the screen.

Please someone help me with this issue, or suggest me a better way to do this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.