I want to bind the Jquery plugin Chosen on a select box that I create via Xajax, the Select does not figure in the DOM when the page is loaded.
So I start by returning the select box and then I execute .chosen() on the box ID:
<? $objResponse = new xajaxResponse();
$objResponse->assign($selectID, 'innerHTML', $codeThatCreatesSelectBox);
$objResponse->script('$(function(){ $("#selectID").chosen(); });');
return $objResponse; ?>
But I’m obviously doing something wrong…
How could I do this ?
EDIT
I tried waiting for ajax returns before firing the plugin by using ajaxComplete() :
$objResponse->script('$("#selectID").ajaxComplete(function() {$("#selectID").chosen(); });');
But it doesn’t change anything..
You can create a callback to do this.
From the documentation: http://www.xajax-project.org/En/docs-tutorials/upgrading-from-xajax-0-2-x-to-0-5/
So you can call your jQuery plugin code inside the desired callback.