* AJAX更新后执行JavaScript * [英] Execute Javascript *after* ajax update

查看:134
本文介绍了* AJAX更新后执行JavaScript *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要执行一个特定的JavaScript函数后,阿贾克斯更新已被应用。我试过 jsf.ajax.addOnEvent(ch.ergon.newom.ajaxUpdate)来 得到通知的要求,但是,这似乎是执行Ajax响应到达后,却之前它得到了应用(即:内容得到更新)。

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

我怎么能执行一个JavaScript函数后的内容得到了由JSF-AJAX更新?

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

推荐答案

事实上,这将是所谓的三倍。一个Ajax请求被发送之前,人们Ajax响应被到达后,一个当AJAX响应成功处理。你需要检查的基础上提供的数据参数的当前状态。你可以在表14-4和14-3的 JSF 2.0规范的技术细节。

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.

下面是你的JS函数应该是什么样子,当你想勾上状态的所有3个开球的例子。

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;
    }
}

或者当你想勾上成功状态只:

function ajaxUpdate(data) {
    if (data.status == 'success') {
        // ...
    }
}

这篇关于* AJAX更新后执行JavaScript *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆