Cjax Framework


Recursive ajax requests demo shows you how you can trigger ajax requests from the server, and if you can trigger an ajax request from the server, then you can do it recursively. First an ajax request is initiated, it goes to the ajax controller. Ajax controller, updates counter, and fires another ajax request to itself. This is truly non-asynchronous because it does not trigger all the requests at once, rather it wait for one to finish, and the ajax request itself triggers the next one until the count total is matched.

Examples


PHP

<?php
$ajax
->click("button1",$ajax->call("ajax.php?recursive_ajax/call/0/|count|"));
?>

<!--HTML-->
<input type='button' id='button1' value ='Start recursive requests'/>
<div id='div_counter'></div>

Try it


How many ajax requests would you like?.



Controller

PHP
<?php 

class recursive_ajax {

    function 
call($counter 0,$count)
    {
        
//force valid inputs
        
$counter = (int) $counter;
        
$count = (int) $count;

        
$counter++;

        
$ajax ajax();

        
//if you enter a number greate than 100
        
if($count 100) {

            
//focus on textbox
            
$ajax->focus('count');

            
//show warning
            
$ajax->warning("Too many requests can add overhead to our servers, please try reducing the number.");

            
//update textbox
            
$ajax->count 30;
            return;
        }

        
//update div
        
$ajax->div_counter "Call# $counter..";

        if(
$counter>=$count) {
            
$ajax->div_counter "$counter recursive AJAX requests were made.";
        } else {

        
//fire call
            
$ajax->call("ajax.php?recursive_ajax/call/$counter/$count");
        }

    }

}

?>

Previous Topic:  Previous Class    ·   Top of Page   ·   Demos Home   ·  

CodeIgniter  ·  Copyright © 2006 - 2012  ·  Cjax