3

I have an ajax commandButton, when i clicked it, it updates the form that i used and call an js function on onclick method.

The problem : a field is invisible at first, i use style="display:none" forinvisibilty. When i click the button, it updates the form data and display:none is still there. On onclick command i use a js function to change the style="display:none to style="display:block".

here is my js function :

setTimeout(function() {
PF('field').jq.css('display', 'block');
}, delay);

I use delay to wait the update finish its job.

here is my command button :

<p:commandButton ajax="true" update="form" onclick="jsFunc();"</p:commandButton>

But i want to be sure when ajax update finish its job, then i want to call the js function.

What is the best way to do this ?

Thanks in advance.

Jasper de Vries
  • 13,693
  • 6
  • 54
  • 86
mstfdz
  • 2,167
  • 3
  • 17
  • 26

2 Answers2

5

Change onclick for oncomplete, the oncomplete event is fire after the update, for more info check this

Community
  • 1
  • 1
David Florez
  • 1,370
  • 2
  • 9
  • 25
-1

you can do it by success method !! example :

    $(".button").click(function(){
        $.ajax({
            type: "POST",
            url: "xxx.php",
            data: {
                'name': data
            },
            success: function(resp) { // resp is the response of php file !
            // something to do after ajax completed !!
            }
        });
});
Komeil Tl
  • 24
  • 7