<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Hello World introduction to Ajax</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="ajax.js"></script>
</head>
<body>
<p id="mySentence"><a href="#" onclick="javascript:sndReq();">Click here</p>
</body>
</html>
#!/usr/local/bin/perl
use CGI;
use CGI qw/:standard/;
my $q= new CGI;
my $pest_name = $q->param("pest");
print $q->header ("text/html"),
$q->start_html("welcome"),
$q->p("From CGI-Bin"),
$q->p("$pest_name"),
$q->end_html;
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() {
http.open('POST', 'cgi-bin/testCGI.pl');
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
alert(response);
document.getElementById('MessBox').value = response;
}
}
|