Home arrow XML arrow Page 5 - 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 - Using POST
(Page 5 of 6 )


Using POST with the request object is a little different. One thing that does not need to change is the format and encoding of the actual information you are sending. In this case, what was the query string is put into the body of the request as an argument to the send method, and the URL remains as an argument to the open method.


var str = "pet=dog";

var url = "http://www.mydomain.com/index.php";// No question mark needed




You will notice if you test this with PHP that the information from this request will not come up in the $_POST or $HTTP_POST_VARS global variables. To access it, you must use $HTTP_RAW_POST_DATA, depending on your php.ini settings. The form of the information will be the string that you sent with the request. In order to use it as key-value pairs, you would have to manually split the string. How this works in ASP, ASP.net, JSP and other server platforms will vary. In order to get the request body values to show up in $_POST as they would from a normal form, you will need to use an additional method of the request object called setRequestHeader().


var str = "pet=dog&hobby=painting";

var url = "http://www.mydomain.com/index.php";// No question mark needed



"application/x-www-form-urlencoded; charset=UTF-8");



Using this header lets the server know that the string of characters in the body of the request is an encoded string of key-value pairs. The information is then handled in the same way as a normal POST form submission.


The open, setRequestHeader and send methods assemble the proper HTTP headers from the information you provide them. The first argument of setRequestHeader is the type of header; the second is the header itself. There is no need to add a ":" between the two, as this is done by the method itself. The header set with this method can be any valid HTTP header.


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-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials