How is AJAX request handled in JSF 2.0?

后端 未结 2 985
暗喜
暗喜 2021-01-15 00:34

I was trying something like below --


     

        
相关标签:
2条回答
  • 2021-01-15 00:43

    This is works for me instead $(document).ajaxComplete();

    RichFaces.jQuery(document).on( 'ajaxcomplete', function(event, xhr, settings){   
         console.log(event, xhr, settings);
          // event, undefined, undefined
    })
    
    0 讨论(0)
  • 2021-01-15 01:00

    The standard JSF impl doesn't use jQuery API to send ajax requests. JSF uses its own internal API which you can find in the auto-included jsf.js file. So the jQuery jQuery.ajaxComplete() is never called. It would only be called when jQuery's $.ajax() (and its shortcuts $.get(), $.post(), etc) is being used. Only jQuery based component libraries use them such as PrimeFaces with <p:commandXxx> and <p:ajax>. For standard JSF <f:ajax>, you need to use JSF's own jsf.ajax.addOnEvent() handler instead, or the onevent attribute of the <f:ajax>.

    In your particular case I think the onevent attribute is mose easy:

    <f:ajax ... onevent="btnOKhandler" />
    

    with

    function btnOKhandler(data) {
        if (data.status == 'success') {
            $.modal.close();
        }
    }
    

    The data.status can have 3 values: begin, complete and success. See also tables 14-4 and 14-3 of the JSF specification.

    See also:

    • Javascript on (before and after) every Ajax-call
    0 讨论(0)
提交回复
热议问题