开发者

Execute Javascript *after* ajax update

开发者 https://www.devze.com 2023-04-08 10:51 出处:网络
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

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?


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') {
        // ...
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号