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

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
TABLE OF CONTENTS:
  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
SEARCH DEVARTICLES

XML in the Browser: Submitting forms using AJAX - The XML in HTTPRequest
(Page 3 of 6 )

 

Though this object has XML in its name, it doesn't necessarily have to use XML. If you wish to use it in an entirely cross platform way, however, consider that currently Apple's Safari requires that the response from the server be of the text/xml mimetype.

 

This may or may not impact your application design. It isn't hard to set up an XML formatted response and code to use the XML data once it's received, but if you were planning on sending text strings only back and forth, this is something to consider. It's likely that the next version of Safari will not have this problem, and working around it is nothing compared to most cross browser DHTML problems. Sending information as a string, on the other hand, works in all platforms and browsers that support the request object.

 

The fact that the request object supports XML allows it to be the gateway for a number of XML based message formats, such as SOAP and XMLRPC, or your own custom solutions. Because the request object uses HTTP, you could also use it with WEBDAV if you were so inclined. If you are only retrieving XML from the server and not sending anything, you can even use AJAX without a server side application platform. The implementation details are up to you, but the tools are there.

 

The Event Handler

 

Whatever event handler function you specify should check for two things. The first is the readyState property. If readyState is 4, then the response has been completely recieved. You then need to check the status property of the request object to determine whether the request was successful. If the value of status is 200, any data that was sent back as a response is ready for use. If status is something other than 200, you will be able to display the error by using the statusText property.

 

The response, as mentioned before, can be a simple text string or an XML document DOM (Document Object Model). The two request object response properties you will use for working with a response are responseText and responseXML. The DOM object stored in responseXML is a completely accessible DOM that can be manipulated and traversed in the same way that your HTML document can be. The responseText property is used when a simple text string is sent by the server.

 

Accessing the XML file through the usual limited DOM methods provided for HTML is no fun. The European Computer Manufacturers Association, or ECMA, who is responsible for the ECMA script standard on which Javascript is based, has just introduced a new extension to ECMA called E4X which is especially designed to work with XML documents. E4X includes support for XPath, which is a W3C recommendation for addressing information within an XML document. Currently, there are no browsers that support E4X. The first browser to support it will be Firefox 1.1. Unfortunately, until E4X truly arrives, traditional DOM methods are all we have.

 


blog comments powered by Disqus
XML ARTICLES

- 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 
Support 

Developer Shed Affiliates

 




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