AJAX - Request a Server
AJAX - Sending a Request to the Server
To send off a request to the server, we use the open() method and the send()
method.
The open() method takes three arguments. The first argument defines which
method to use when sending the request (GET or POST). The second argument
specifies the URL of the server-side script. The third argument specifies that
the request should be handled asynchronously. The send() method sends the request off to the
server. If we assume that the HTML and ASP file are in the same directory, the code
would be:
xmlHttp.open("GET","time.asp",true);
xmlHttp.send(null);
|
Now we must decide when the AJAX function should be executed. We will let the
function run "behind the scenes" when the user types something in the username
text field:
<form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>
|
Our updated AJAX-ready "testAjax.htm" file now looks like this:
<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==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","time.asp",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>
|
The next chapter makes our AJAX application complete with the "time.asp"
script.
The Ektron Intranet
lets you do everything you need to do on your corporate intranet and everything you want to do... all with just one application.
What can you do with the Ektron Intranet? |

|
Navigate through content, documents, assets, colleagues and workgroups quickly and intuitively with enterprise search |

|
Communicate with friends and colleagues with forums, message boards and corporate blogging using the new Social Networking Platform |

|
Promote collaboration among coworkers in your organization through project workspaces where others can efficiently find information and work together |

|
Personalize your company profile by bookmarking and organizing favorite content, uploading assets, posting photos, blogging, and more |

|
Interact with features like tagging, flagging, wikis and ratings found in the Web 2.0 Toolbox |
 |
Author/edit content, manage navigation, menus, audit trails, workflow and approvals with the best in breed Content Management |
|
|
|
|
See why there are 20,000+ Ektron integrations worldwide. Request an
INSTANT DEMO or download a
FREE TRIAL today. |
|