VisualBuilder
  Home > Ajax > Tutorials > Using XMLHttpRequest object to send xml message - Learn AJAX Tutorial
Tell a friend
Link to us
Total Members
      Members: 84606
     
Sitemap Forum Chat
Home
Learn AJAX Tutorial Home
1 . Introduction to AJAX
2 . AJAX web model
3 . Submitting a Request
4 . Benefits of AJAX
5 . Role of JavaScript
6 . Java Script in relation to HTML
7 . How does AJAX work
8 . AJAX Application
9 . Examples of AJAX
10 . Code Example for creating an AJAX application
11 . Using XMLHttpRequest object to send xml message
12 . Create service responding to http request
13 . Parsing xml response and update DOM object
14 . Screen shots of running an AJAX example
15 . Example for parsing XML message
16 . Building response XML message in server
17 . Parsing XML message and update to DOM
18 . XmlHttpRequest object,how to use?
19 . Object methods
20 . Object properties of XMLHttpRequest object
21 . Making asynchronous requests with JavaScript and AJAX
22 . Suitability of the synchronous and asynchronous models
23 . AJAX Frameworks
 
Ajax Group Home
Ajax Discussion (7)
Ajax Members (2339)
Ajax Resources
Ajax Source Code (4)
Ajax Articles (1)
Ajax Blogs
Ajax Jobs
Ajax Components (6)
Ajax Books
Ajax Websites (26)
Ajax News (7)
Ajax Q & A (12)
- Ajax Ask Question
- Ajax Questions
- Ajax Unanswered Questions
 
GROUPS
.NET
ASP.NET
.NET
C#
ASP
Visual Basic
Java
Java
JSP
EJB
Other
Delphi
C++
Ajax
UML
JavaScript
PHP
Web Design
Web Hosting
SQL Server
Oracle
Project Management
More Groups

 
LEARNING CENTER
TUTORIALS
.NET
.NET Tutorial
ASP Tutorial
ASP.NET Database Tutorial
ASP.NET Development Tips
ASP.Net Security,Internationalisation And Deployment
ASP.NET Server Controls Tips
ASP.NET Tutorial
C Sharp Tutorial
Web Development
Flex Tutorial
HTML Tutorial
Learn AJAX Tutorial
PHP Tutorial
Software Development
Database Tutorial
SQL Tutorial
UML Tutorial
Java
Ant Tutorial
EJB 3 Tutorial
Hibernate Tutorial
Java Tutorial
Java Web Component Tutorial
Java XML Tutorial
JDBC Tutorial
JDK1.5 Tutorial
JSF Tutorial
JSP And J2EE Design Tutorial
JSP Tutorial
Spring Tutorial
Struts Tutorial

RESOURCES
Q & A (432 )
Source Code (3217 )
Articles (11 )
Components (1589 )
News (880 )
Websites (1207 )

SUBMISSIONS
Submit Article
Submit Website
Submit News
Submit Source Code
Submit Component

COMMUNITY
Members Directory
Discussion Forum
Chat

SITE
About Us
Sitemap
Search
Contact Us
Link To Us
Feedback
Tell a Friend
Partners
Advertise


Ajax Tutorial
 Using XMLHttpRequest object to send xml message
  << Prev: Code Example for creating an AJAX application Next: Create service responding to http request >>

Using XMLHttpRequest object to send xml message

Firstly,the login page is presented (login.jsp) where the user types and receives the status immediately afterwards.


When the user is typing in the username textbox,the onKeyUp event is sent and the JavaScript function validateUse() will be invoked,as written in following:



<input type="text" id="user_name" onKeyUp="validateUser()">



In the validateUser method,an instance of XMLHttpRequest will be created:
if (window.ActiveXObject)
{
 oXMLRequest = new ActiveXObject("Microsoft.XMLHTTP");  
}
else
{
oXMLRequest = new XMLHttpRequest();
}    


There are two ways of creating an instance of XMLHttpRequest object. They deal with the different kinds of browser,one for Internet Explorer and one for the other browsers such as Mozilla,Safari.


The instance of XMLHttpRequest object is used to send the XML request,and receive the response. Before sending,it must be known where the service on web server located the message and the sending method. The code below is an example for setting up the request:


var strUserName = document.getElementById("user_name").value;
var strValidationServiceUrl = "user.UserValidator?UserName=" + strUserName;


oXMLRequest.open("GET",strValidationServiceUrl,true);
oXMLRequest.onreadystatechange = updateDOM;
oXMLRequest.send(null);
   


1. The Open Method:
  The open method is to identify:

- The URL of destination service running on web server,
- Sending method is the http method,typical value is GET or POST but can also be HEAD
- Boolean value identifies that communication between XMLHttpRequest and web server is asynchronous or not


The property onreadystatechange is to specify the method to update the DOM object of the HTML page. This method will be invoked immediately after receiving the response from the web server. In the code above it’s the updateDOM.


2. The Send Method:
The send method is used to send a request to the service specified in URL,value of input parameter is content of the request. In this case,the URL parameter is used to tell the web server what is required instead of the XML message,so the XML message is set as null.
 


  << Prev: Code Example for creating an AJAX application Next: Create service responding to http request >>
Ajax Tutorial Home
Give feedback and win a prize.

 
   Printer Friendly
   Email to a friend
   Add to my Favourites    
  Download PDF version
   Report Bad Submissions
   Submit Feedback
 
  Delicious   Digg   Technorati   Blink   Furl   Reddit   Newsvine   Google Click each image to add
this page to each site.
 
 
Welcome Guest Signup
MEMBER'S PANEL
EMAIL
PASSWORD
Forgot your password?
New User? Click Here!
 
Resend Activation Email!
 
SEARCH
 
 
LINKS
MSN
Video Surveillance
Hosted Exchange, SDSL
Gift to Pakistan
 
ADVERTISEMENT
 
PARTNER LIST

More
 
 
 

Home | Login | About Us | Contact Us | Privacy Policy | Advertising