Call() takes the following parameters
array Cjax 5.9+
|This url is fetched with ajax|
|$container_id||No||String||div, span, p, td, etc
You must echo your desire content from the controller/method.
|Update a specific container with this pararement, any text the ajax call comes back with in the response will be automatically propagated to this container.|
|$confirm||No||String||string $message||Need to ask "Are you sure?" Before triggering the call() ?|
Simple UsageYou can use the call() method without any other parameters. It will trigger the ajax request in the instant.
//As of 5.9 you can do this way
More UsagesYou can use the call() method with any of the Cjax trigger events.
//the most common usage
//used in a text-type field.
//used in a text-type field. In keyup event, basically every time you type
Cjax 5.9+The call method remains the same with the exception of the url$ argument, which now supports arrays as well as the previous method. As of Cjax 5.9, you can pass an array to the url$ argument specifying a controller and a method, and additional options. Passing an array allows you to enter the controller , method, without specifying the dispatcher file ajax.php.
You can pass a 3rd parameter in the array to pass element values, generelly you would pass these in the url in between pine lines eg. |text1| would send the value of a text field which id is text1. You may pass one parameter, a string or you can pass an array of element, to pass their value. If the element is not found on the page, the raw text will be passed.
//pass array with controller, method and one value
//pass array with controller, method and multiple values
$values = array('text1','text2', 12345);
$ajax->click('#link_values', $ajax->call(array('controller','method', $values));
In the example above, we send text1, text2, and 12345. Since text1 element id exists, it passes its value, and text2 does not exist, it just passes the raw text, all numeric values are passed as they are.
Options / CachingThe $url parameter used as a array as explained in the previous section can support even more parameters.
One of the parameter is $options parameter. Currently $options only have one option called cache.
This cache option, lets you specify whether you want Cjax to cache the current ajax request. The ajax request is cached by saving the url as a unique key, so if you make more than one request to the same url, the response of the first request is always returned. If the url changes, then it will go through the same process. Say if you are sending a different id on within the same ajax request it will cache each one of these calls, the second call to the same url doesn't make it to the server, instead the first response is re-used.
$ajax->click('#text3', $ajax->call(array('controller','method', null, array('cache' => true)));
ContainerThe call() method contains 3 parameters and on itself, and the first parameter $url can be used in two different ways. As a string and as an array.
This method also has other two parameters $container_id, which allows pass a container id, (a div, span, td, etc) which you would want to be updated with the response of the ajax call. If you intend to update something specific on the page this is a straight forward way to do it. For this to work, you will need to echo the content inside the controller method.
$ajax->click('#link_container', $ajax->call(array('call','container'), 'my_div'));
ConfirmThe last parameter method call() uses is $confirm. With this youu can ask as user if he is sure he wants to continue, and if the user clicks Ok, the ajax request continues, otherwise it cancels.
$ajax->click('#link_confirm', $ajax->call(array('call','confirm'), null,'Are you absolutely sure you want to continue?'));
Test (Click Ok)