+ Start a Discussion
Mahesh K 22Mahesh K 22 

I Need best exemples and senarios of ajax functions

Hi To All
       
              i would like to know of ajax function like Action Function,Action Status,Action Region,ActionPollar,Action Support,
           How it works and when these can be use?????????
sfdcMonkey.comsfdcMonkey.com
hi Mahesh K 22
A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An <apex:actionFunction> component must be a child of an <apex:form> component.
Unlike <apex:actionSupport>, which only provides support for invoking controller action methods from other Visualforce components, <apex:actionFunction> defines a new JavaScript function which can then be called from within a block of JavaScript code.

Note: Beginning with API version 23 you can't place <apex:actionFunction> inside an iteration component — <apex:pageBlockTable>, <apex:repeat>, and so on. Put the <apex:actionFunction> after the iteration component, and inside the iteration put a normal JavaScript function that calls it.

Example
<!-- Page: -->
                       
<apex:page controller="exampleCon">
    <apex:form>
        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>
    </apex:form>

    <apex:outputPanel id="out">
    <apex:outputText value="Hello "/>
    <apex:actionStatus startText="requesting..." id="myStatus">
        <apex:facet name="stop">{!username}</apex:facet>
    </apex:actionStatus>
    </apex:outputPanel>
           
    <!-- Call the sayHello JavaScript function using a script element-->
    <script>window.setTimeout(sayHello,2000)</script>
           
    <p><apex:outputText value="Clicked? {!state}" id="showstate" /></p>
           
    <!-- Add the onclick event listener to a panel. When clicked, the panel triggers
    the methodOneInJavascript actionFunction with a param -->
    <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn">
        Click Me
    </apex:outputPanel>
    <apex:form>

    <apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate">
        <apex:param name="firstParam" assignTo="{!state}" value="" />
    </apex:actionFunction>
    </apex:form>
</apex:page>


 
/*** Controller ***/
public class exampleCon {
    String uname;

    public String getUsername() {
        return uname;
    }
           
    public PageReference sayHello() {
        uname = UserInfo.getName();
        return null;
    }
           
    public void setState(String n) {
        state = n;
    }
           
    public String getState() {
        return state;
    }
           
    public PageReference methodOne() {
        return null;
    }
           
    private String state = 'no';
}

Thanks 

If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer. :)