I visited the ajax tutorial in w3cschools yesterday, the following html is mostly copied directly from that tutorial:
---------------------------------------------------------------------------
<html>
<head>
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML= "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange= function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML= xmlhttp.responseText;
}
};
xmlhttp.open("GET", "....cgi-bin/ajax_tst.cgi?str=" + str, true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<p><b>Start typing a letter in the input field below:</b></p>
<form>
enter a lettr: <input type="text" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
------------------------------------------------------------
The following perl is my 1st try to run on my server
------------------------------------------------------------
#!/usr/bin/perl
use strict;
use CGI;
our $qq= new CGI;
print $qq->header("text/xml"); # I have tried to not print this, but failed also
my $str=$qq->param("str");
#print "<?xml version='1.0'?><response>you entered $str</response>"; # I tried this one but did not work
#print "you entered $str"; # tried this one also did not work
print "<html><body>you entered $str</body></html>"; # neither this one works
open(OUT,">/var/ # for debugging
print OUT "seeing $str\n"; # I saw the correct result on my server, proving that ajax has transferred the str from browser to server correctly
1;
---------------------------------------------------------------
But this perl did not correctly transfer the result back to the browser,
What is the problem?
Thank you in advnace for helping!
---------------------------------------------------------------------------
<html>
<head>
<script>
function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML= "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange= function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML= xmlhttp.responseText;
}
};
xmlhttp.open("GET", "....cgi-bin/ajax_tst.cgi?str=" + str, true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<p><b>Start typing a letter in the input field below:</b></p>
<form>
enter a lettr: <input type="text" onkeyup="showHint(this.value)">
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
------------------------------------------------------------
The following perl is my 1st try to run on my server
------------------------------------------------------------
#!/usr/bin/perl
use strict;
use CGI;
our $qq= new CGI;
print $qq->header("text/xml"); # I have tried to not print this, but failed also
my $str=$qq->param("str");
#print "<?xml version='1.0'?><response>you entered $str</response>"; # I tried this one but did not work
#print "you entered $str"; # tried this one also did not work
print "<html><body>you entered $str</body></html>"; # neither this one works
open(OUT,">/var/ # for debugging
print OUT "seeing $str\n"; # I saw the correct result on my server, proving that ajax has transferred the str from browser to server correctly
1;
---------------------------------------------------------------
But this perl did not correctly transfer the result back to the browser,
What is the problem?
Thank you in advnace for helping!