1

In my button click, action method is not invoking in action function and directly going to oncomplete method.Below is the code. Controller -

function cheValidation(){
    callService();
}

function closePage(){
    var responseValue='{!resp}';
    alert(responseValue);
    var status='{!sta}';

    if(status==='Pass'){

    }else{
    //alert("Fail");
   } 
}

VF Page -

<apex:actionFunction name="callService" action="{!asMethod}" rerender="script"  status="loading" oncomplete="closePage();"/>
<apex:actionStatus id="loading" onstart="loading(true)" onstop="loading(false)" />    
<apex:commandButton value="Submit" rerender="theForm" onclick="return cheValidation();" />

when first time clicking its working fine, displaying alert after method.but second time click it directly goes to oncomplete method and displaying previous alert. its not invoking action function.

Does anyone have any idea about this issue?

1

I believe the form is being submitted.

Try updating your button to be <button type="button"> instead of an apex:commandbutton. Alternatively return false from your JS or use e.preventdefault()

You might want to look into JS remoting for this use case where you want to handle the response. It's cleaner than re-rendering a script block

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.