bilischan88
11-03-2007, 12:56 AM
So I've been at this ajax problem for a month now, which should show you how new I am to it. Anyways, everything looks as right as all the ajax tutorials out there say it should be but for some reason it doesn't give me a response. I've simplified the response to a date now as to show how nothing gets passed back to the frontpage. Here's the scripts:
Javascript:
var xmlHttp;
function createXMLHttpRequest(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch(e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
// Something went wrong
alert ("Browser does not support HTTP Request");
return false;
}
}
}
return ajaxRequest;
}
function eventHorizon(){
document.getElementById("cont").innerHTML="Starting...";
xmlHttp=createXMLHttpRequest();
var url="ajax-supp.php";
xmlHttp.onreadystatechange=callback
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function callback(){
if (xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById("cont").innerHTML=xmlHttp.responseText;
}else{
document.getElementById("cont").innerHTML="Cannot find page: " + xmlHttp.status;
}
}else{
document.getElementById("cont").innerHTML="Waiting for server...";
}
}
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<title>Ajax Test</title>
<script ltype="text/javascript" src="ajax.js"></script>
</head>
<body>
<div id="cont" style="border:#000000 solid thin;">
hello
</div>
<br />
<a href="" onclick="eventHorizon()">-Show</a>
</body>
</html>
and the PHP:
<?php
echo date("H:i:s");
?>
Please let me know what's wrong with this.
Edit: here's a link (http://netwack.com/test/ajax.php) if you want to try it out yourself.
Javascript:
var xmlHttp;
function createXMLHttpRequest(){
var ajaxRequest; // The variable that makes Ajax possible!
try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
}catch(e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
// Something went wrong
alert ("Browser does not support HTTP Request");
return false;
}
}
}
return ajaxRequest;
}
function eventHorizon(){
document.getElementById("cont").innerHTML="Starting...";
xmlHttp=createXMLHttpRequest();
var url="ajax-supp.php";
xmlHttp.onreadystatechange=callback
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
function callback(){
if (xmlHttp.readyState==4){
if(xmlHttp.status==200){
document.getElementById("cont").innerHTML=xmlHttp.responseText;
}else{
document.getElementById("cont").innerHTML="Cannot find page: " + xmlHttp.status;
}
}else{
document.getElementById("cont").innerHTML="Waiting for server...";
}
}
HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<title>Ajax Test</title>
<script ltype="text/javascript" src="ajax.js"></script>
</head>
<body>
<div id="cont" style="border:#000000 solid thin;">
hello
</div>
<br />
<a href="" onclick="eventHorizon()">-Show</a>
</body>
</html>
and the PHP:
<?php
echo date("H:i:s");
?>
Please let me know what's wrong with this.
Edit: here's a link (http://netwack.com/test/ajax.php) if you want to try it out yourself.