Home arrow JavaScript arrow Page 6 - Submission Throttling and the Browser-Server Dialogue
JAVASCRIPT

Submission Throttling and the Browser-Server Dialogue


The second part of this series of articles dealing with browser-server information flow discussed periodic refreshing. This one covers submission throttling and explicit submission. The third of a multi-part series, this article is excerpted from chapter 10 of the book Ajax Design Patterns, written by Michael Mahemoff (O'Reilly, 2006; ISBN: 0596101805).

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
October 19, 2006
TABLE OF CONTENTS:
  1. · Submission Throttling and the Browser-Server Dialogue
  2. · Decisions about Submission Throttling
  3. · Real-World Examples of Submission Throttling
  4. · Explicit Submission
  5. · Decisions about Explicit Submission
  6. · Real-World Examples of Explicit Submission
  7. · Alternatives to Explicit Submission

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



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