XML
  Home arrow XML arrow Page 5 - XML in the Browser: Submitting forms using...
Iron Speed
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Download TestComplete 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
IBM Rational Software Development Conference
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
XML

XML in the Browser: Submitting forms using AJAX
By: Chris Root
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 157
    2005-04-25

    Table of Contents:
  • XML in the Browser: Submitting forms using AJAX
  • What's Out There Now
  • The XML in HTTPRequest
  • HTTP Methods
  • Using POST
  • Submitting a Form

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    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

    xmlReq.open("POST",url,true);

    xmlReq.send(str);

     

    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

    xmlReq.open("POST",url,true);

    xmlReq.setRequestHeader("Content-Type",

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

    xmlReq.send(str);

     

    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.

     

    More XML Articles
    More By Chris Root


       · this is just what I was looking for, but I found a few error's or something what...
       · I was using XMLHttpRequest from javascript through hidden frames to get/put to the...
       · The permissions error is caused by trying to run that script off of your own...
       · Hi,I am able to send the request to the server. But the problem is I dont know how...
       · It would be handled as any http request would be. I don't do a lot of JSP but I...
       · I almost forgot. JSP has a Request object for recieving the request. The...
       · Hi: How can i upload a file using the ajax form method ??? thanks for your...
       · You mention in XML in the Browser: Submitting forms using AJAX - HTTP Methods...
       · request = new ActiveXObject("Microsoft.XMLHTTP"); request.onreadystatechange =...
       · You're current script does not support radio buttons. The POST/GET will return the...
       · Great tutorial,i've used this script, and i found that it doesn't preserve special...
       · The W3C specifications state that any form object that is disabled cannot be...
       · Hi, the radio part of the last post is not working for me. I'm getting a Javascript...
       · I'm having the same problem.. Any solutions? Thanks!
       · Hello,This is how I made the radio button case work correctly in IE 6 sp2....
       · Sorry about that, as I said, I never tried out all the types. Thanks for pointing it...
       · I have done some testing and have found multiple selects don't work correctly...
       · But where is the displayState function that is needed to get the values returned...
       · That would be your AJAX script which this article does not address. Whatever you are...
       · At least as far as i know...Please correct me if I'm wrong.
       · Hmm this new GetFormValues function made my code stop working..Not sure why at...
       · Ahh got it working..Thanks heaps for your code. Much appreciated, saved me lots...
       · Hello,Could you please send a link to the complete script.Thanx in...
       · My changed version with testing html...
     

    XML ARTICLES

    - Path, Predicates, and XQuery
    - Using Predicates with XQuery
    - Navigating Input Documents Using Paths
    - XML Basics
    - Introduction to XPath
    - Simple Web Syndication with RSS 2.0
    - Java UI Design with an IDE
    - UI Design with Java and XML Toolkits
    - Displaying ADO Retrieved Data with XML Islan...
    - Widget Walkthrough
    - Introduction to Widgets
    - The Why and How of XML Data Islands
    - Creating an XUL App Installer
    - Overlays in XUL
    - Skinning Your Custom XUL Applications






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway