XML
  Home arrow XML arrow Page 4 - XML in the Browser: Submitting forms using...
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  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 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 / 162
    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
     
    Iron Speed
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    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.

     

    http://www.mydomain.com?id=215&status=true

     

    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";

    xmlReq.open("GET",str,true);

     

    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.

     

    xmlReq.send(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.

     

    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


    Iron Speed





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