0

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..

1 Answer 1

1

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/

myCallback = xajax.callback.create(100, 10000);
myCallback.onRequest = function()
{
    xajax. $('loadingMsg').style.display = 'block';
};
myCallback.onComplete = function()
{
    xajax. $('loadingMsg').style.display = 'none';
};

// then, on the PHP side, specify the callback option when registering your function:
$xajax->register(XAJAX_FUNCTION, 'myFunction', array(
    'callback' => 'myCallback'
));

So you can call your jQuery plugin code inside the desired callback.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.