Advertisement

07.04.2008 at 11:17PM PDT, ID: 23540368
[x]
Attachment Details

Need a simple ajax example

Asked by cyberwebservice in Asynchronous Javascript and XML (AJAX)

I tried testing some ajax examples in my server. But nothing seems to work.

So, I need a simple tested ajax example to test on my server preferably using php script.

I have attached a simple example from w3schools.com which i am testing in my hosting servers. I do not know if anything wrong with the script or i need to do something at the server side.

Any help is appreciated.
Thanks.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
<html>
<body>
 
<script type="text/javascript">
function ajaxFunction()
{
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;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==0)
      {
	//0	The request is not initialized
	//1	The request has been set up
	//2	The request has been sent
	//3	The request is in process
	//4	The request is complete
      document.myForm.time.value=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","test.php",true);
  xmlHttp.send(null);
  }
</script>
 
<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>
 
</body>
</html>
 
 
---------------------------------------------------------
test.php
 
<?
echo date('h:i a');
?>
 
Loading Advertisement...
 
[+][-]07.05.2008 at 01:45AM PDT, ID: 21936363

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Asynchronous Javascript and XML (AJAX)
Sign Up Now!
Solution Provided By: hielo
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.05.2008 at 02:05AM PDT, ID: 21936396

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 03:18AM PDT, ID: 21936517

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.05.2008 at 05:05AM PDT, ID: 21936722

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906