Home arrow XML arrow Page 4 - XML in the Browser: Submitting forms using AJAX

XML in the Browser: Submitting forms using AJAX

One of the least user friendly features of most websites is forms. The longer the form, the more annoying it gets. However, a new technology called AJAX (that has nothing to do with household cleansers!) can help.

Author Info:
By: Chris Root
Rating: 4 stars4 stars4 stars4 stars4 stars / 211
April 25, 2005
  1. · XML in the Browser: Submitting forms using AJAX
  2. · What's Out There Now
  3. · The XML in HTTPRequest
  4. · HTTP Methods
  5. · Using POST
  6. · Submitting a Form

print this article

XML in the Browser: Submitting forms using AJAX - HTTP Methods
(Page 4 of 6 )


The request object supports both POST and GET as well as other HTTP methods.


Using the GET method is the simplest to implement.


In a GET request, all information is contained in the URL. It is encoded to escape characters and spaces that are not allowed in URLs by representing them as their hexadecimal equivalents preceded by "%". The information is formatted as key-value pairs in the following way.




To encode a value you can use the Javascript function escape(). To encode an entire URL, use encodeURI. Keep in mind that encodeURI is part of Javascript 1.5, and is only supported by browsers that also support this version of Javascript.


Once you have a properly formatted string of values that has been tacked onto the end of the URL, you can use the open method of the request object to start the process of sending the request.


var str = "http://www.mydomain.com/index.php?pet=dog&hobby=painting";



The variable str is shown here as a hard coded string, however in practice it's likely that you will be compiling it from other code. The open method takes three arguments. The first is the HTTP method as a string. The second is the URL string, and the third is a boolean value. This third parameter determines whether or not the request is done asynchronously. If the need arises to ask the user to wait for a request to finish, you could set this argument to false; otherwise, it should be set to true.


The send() Method


The send method is the final stage for sending the request. It takes one argument but in the case of a GET request that value is not needed. Instead this argument should be null.




If you were using the POST method, the argument for send() can be a string or an XML DOM object. This allows you to send a string of text or a serialized XML document as part of the body of your request.


blog comments powered by Disqus

- Open XML Finally Supported by MS Office
- XML Features Added to Two Systems
- Using Regions with XSL Formatting Objects
- Using XSL Formatting Objects
- More Schematron Features
- Schematron Patterns and Validation
- Using Schematron
- Datatypes and More in RELAX NG
- Providing Options in RELAX NG
- An Introduction to RELAX NG
- Path, Predicates, and XQuery
- Using Predicates with XQuery
- Navigating Input Documents Using Paths
- XML Basics
- Introduction to XPath

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials