-
July 13th, 2007, 12:01 AM
#1
Ajax with PHP
I'm trying to write the server side script in PHP. The following code is supposed to show the value returned by time() inside a text box. But it is not doing that. Where is the problem?
Client Side Ajax Script:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Ajax Practice</title>
<script type="text/javascript">
function GetXmlHttpObject() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
function ajaxFunction() {
var xmlHttp = GetXmlHttpObject();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {// The request is complete
document.myForm.time.value = xmlHttp.responseText;
}
}
xmlHttp.open("GET", "http://localhost/time.php", true);
xmlHttp.send(null);
}
</script>
</head>
<body>
<form name="myForm">
Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>
</body>
</html>
Server Side PHP Script:
Code:
<?php
print time();
?>
I'm using XAMPP and the file time.php is placed in C:\Program Files\XAMPP\xampp\htdocs. When I open http://localhost/time.php, it is showing correct result.
Please help.
~Donotalo()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|