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:
Server Side PHP 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>
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.Code:<?php print time(); ?>
Please help.


Reply With Quote
Bookmarks