Total members 11894 |It is currently Thu Nov 21, 2024 12:22 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





AJAX - Sending a request to a server
To send off a request to the server, we use the open() and send() methods.

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:
javascript code
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 a user types something in the "Name" field:
html code
<form name="myForm">
Name: <input type="text" name="username" onkeyup="ajaxFunction();" />
Time: <input type="text" name="time" />
</form>

Our updated "testAjax.htm" file now looks like this:
html code
<html>
<body>

<script type="text/javascript">
function ajaxFunction()
{
var xmlhttp;
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
alert("Your browser does not support XMLHTTP!");
}
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" name="username" onkeyup="ajaxFunction();" />
Time: <input type="text" name="time" />
</form>

</body>
</html>





Author:
Newbie
User avatar Posts: 23
Have thanks: 1 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : AJAX - Sending a request to a server
 Sending a post request using AJAX     -  
 Sending One lakh character in ajax     -  
 Ajax Source code to Suggest application with JSP Server side     -  
 Sql server or windows server question?     -  
 sending sms from bluetooth mobile to pc     -  
 Help Sending e-mail from VB.Net application     -  
 sending parameters into XSLT sheet     -  
 Sending and playing microphone audio over network     -  
 What is AJAX, How to start AJAX?     -  
 sending sms using java code and bluetoth device pls send the     -  



Topic Tags

AJAX Request






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com