JavaScript
  Home arrow JavaScript arrow Page 6 - Submission Throttling and the Browser-Serv...
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  
Mobile Linux 
App Generation ROI 
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? 
JAVASCRIPT

Submission Throttling and the Browser-Server Dialogue
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2006-10-19

    Table of Contents:
  • Submission Throttling and the Browser-Server Dialogue
  • Decisions about Submission Throttling
  • Real-World Examples of Submission Throttling
  • Explicit Submission
  • Decisions about Explicit Submission
  • Real-World Examples of Explicit Submission
  • Alternatives to Explicit Submission

  • 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


    Submission Throttling and the Browser-Server Dialogue - Real-World Examples of Explicit Submission


    (Page 6 of 7 )

     

    Lace Chat

    Brett Stimmerman's Lace Chat (http://www.socket7.net/lace/) is an Ajax chat application. Lace users type the entire message and then explicitly submit with a Say button. You can also hit Enter after typing the message. Most chat applications work this way. It's a little more efficient, but the main benefit is actually for the user. It might be confusing to other users to see a partially constructed message, so the composer of that message should rectify any errors before posting the message.

    The Fonz

    "The Fonz" text adventure (http://www.mrspeaker.webeisteddfod.com/2005/04/17/the-fonz-and-ajax/) is a command-line game (Figure 10-7). In typical command-line fashion, you type something and submit the whole command at once. Interestingly, command lines don't have to work that way--it's feasible to provide hints or some validation support as the user types. The Assistive Search Demo (http://ajaxify.com/run/assistiveSearch/) illustrates this point.


    Figure 1-7.  The Fonz

    A9

    A9 (http://a9.com), as with many search engines, requires Explicit Submission before it searches for the user's query (Figure 10-8).


    Figure 10-8.  A9 search

    Code Refactoring: AjaxPatterns Form-Based Sum

    The Basic Sum Demo (http://ajaxify.com/run/sum) illustrates Explicit Submission. In the basic case, there are some input fields and a button, just sitting in a div:

      <div>

        <div id="figure">
          <input type="text" class="figure" id="figure1"
                  name="figure1" size="3" value="4"/><br/>
          <input type="text" class="figure" id="figure2"
                  name="figure2" size="3" value="6"/><br/>
          <input type="text" class="figure" id="figure3"
                  name="figure3" size="3" value="" /><br/>
        </div>

        <input type="button" id="addButton" value="Add" />

      </div>

    The button is configured to submit the form when it is clicked, an example of Explicit Submission:

      $("addButton").onclick = function() {
        submitSum();
      }

    We now refactor to an alternative form of Explicit Submission, in which a standard form (http://ajaxify.com/run/sum/form) makes the submission. It's still an "Ajax submission" involving no page refresh, but it leverages the standard form mechanism. There are two reasons you might do this in real life: it's a step towards graceful degradation, since non-JavaScript browsers will require the data to be held in a standard form; it will "feel" more like a form to the user--e.g., the Enter key will automatically submit, and any CSS styling for forms will apply to it.

    The initial HTML has been wrapped by a form tag. With standard JavaScript enabled, the action URL makes no difference because it will never be accessed, but if we want, we could point it to a conventional server-side script that would process the form in the event that JavaScript is turned off. The regular button control has been replaced by a submit button:

      <form action="http://ajaxify.com/run/sum/form/">

        <div id="figure">
          <input type="text" class="figure" id="figure1"
                  name="figure1" size="3" value="4"/><br/>
          <input type="text" class="figure" id="figure2"
                  name="figure2" size="3" value="6"/><br/>
          <input type="text" class="figure" id="figure3"
                  name="figure3" size="3" value="" /><br/>
        </div>

        <input type="submit" id="addButton" value="Add" />

      </form>

    The script hooks into onsubmit , which will be called when the new submit button is clicked. It arranges for an XMLHttpRequest submission via submitSum() , then returns false to prevent a conventional form submission and page refresh.

      $("sumForm").onsubmit = function() {
       
    submitSum();
       
    return false;
     
    }

    More JavaScript Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Ajax Design Patterns," published by...
     

    Buy this book now. This article is excerpted from chapter 10 of the book Ajax Design Patterns, written by Michael Mahemoff (O'Reilly, 2006; ISBN: 0596101805). Check it out today at your favorite bookstore. Buy this book now.

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT