1

I need to execute a certain javascript function after the ajax update has been applied. I tried jsf.ajax.addOnEvent(ch.ergon.newom.ajaxUpdate) to get informed about the request, but that seems to be execute after the ajax response arrived, but before it got applied (that is: the content got updated).

How can I execute a JavaScript function after the content got updated by JSF-ajax?

1 Answer 1

2

Actually, this will be called three times. One before the ajax request is sent, one after the ajax response is arrived and one when the ajax response is successfully processed. You need to check the current status based on the provided data argument. You can find technical details in tables 14-4 and 14-3 of the JSF 2.0 specification.

Here's a kickoff example of how your JS function should look like when you'd like to hook on all 3 of the statuses.

function ajaxUpdate(data) {
    var ajaxStatus = data.status; // Can be 'begin', 'complete' and 'success'.

    switch (ajaxStatus) {
        case 'begin': // This is called right before ajax request is been sent.
            // ...
            break;

        case 'complete': // This is called right after ajax response is received.
            // ...
            break;

        case 'success': // This is called when ajax response is successfully processed.
            // ...
            break;
    }
}

Or when you'd like to hook on the success status only:

function ajaxUpdate(data) {
    if (data.status == 'success') {
        // ...
    }
}
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.