Source for file queue_usage.php
Documentation is available at queue_usage.php
* Example of Using HTML_AJAX with a queue
* When using HTML_AJAX your actually always using a queue, its just its a simple one that always performs whatever actions its given immediately
* HTML_AJAX however provides other queues offering different modes of operation
* Currently the Queues are (class names are prefixed with: HTML_AJAX_Queue_):
* Immediate - Default make the request immediately
* Interval_SingleBuffer - Make request on an interval with holding just the last request between calls
* Interval_SingleBuffer is generally used for Live Search/Google Suggest type operations
* @author Joshua Eichorn <josh@bluga.net>
* @copyright 2005 Joshua Eichorn
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: 0.5.4
* @link http://pear.php.net/package/HTML_AJAX
<script type='text/javascript' src="server.php?client=Util,main,dispatcher,httpclient,request,json,loading,iframe,queues"></script>
<script type='text/javascript' src="auto_server.php?stub=livesearch"></script>
<script type="text/javascript">
// callback hash, outputs the results of the search method
search: function(result) {
// if we have object this works right, if we have an array we get a problem
// if we have sparse keys will get an array back otherwise will get an array
if (i != '______array') {
out += "<li>"+i+" = "+result[i]+"</li>";
document.getElementById('target').innerHTML = out;
// setup our remote object from the generated proxy stub
var remoteLiveSearch = new livesearch(callback);
// we could change the queue by overriding the default one, but generally you want to create a new one
// set our remote object to use the rls queue
remoteLiveSearch.dispatcher.queue = 'rls';
// create the rls queue, with a 350ms buffer, a larger interval such as 2000 is useful to see what is happening but not so useful in real life
HTML_AJAX.queues['rls'] = new HTML_AJAX_Queue_Interval_SingleBuffer(350);
// what to call on onkeyup, you might want some logic here to not search on empty strings or to do something else in those cases
function searchRequest(searchBox) {
remoteLiveSearch.search(searchBox.value);
<p>This is a really basic LiveSearch example, type in the box below to find a fruit</p>
Search <input id="search" autocomplete="off" onkeyup="searchRequest(this)">
<div style="white-space: pre; padding: 1em; margin: 1em; width: 600px; height: 300px; border: solid 2px black; overflow: auto;" id="target">Target</div>
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
Documentation generated on Fri, 04 Apr 2008 18:30:23 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.
|