Activity Forums Salesforce® Discussions What is AJAX typically used for in Salesforce Visualforce pages?

  • Anjali

    Member
    August 8, 2018 at 1:13 pm

    Hi Suniti,

    Visualforce has inbuilt support for the AJAX. using the attribute “rerender” we can specify that where the response should be rendered.

    Lets have an example to demonstrate that how simple AJAX works in visualforce.

    public class AjaxDemo {

    private String currTime;
    public String getCurrTime()
    {
    return currTime;
    }
    public void setCurrTime()
    {
    currTime = System.now().format('EEEE, MMMM d, yyyy - hh:mm:ss');
    }
    }

    On the basis of above Apex class lets create Visualforce page with below code.

    <apex:page Controller="AjaxDemo">
    <apex:pageBlock Title="Ajax Sample">
    Hello <b> {!$User.FirstName}</b>.
    <apex:form >
    <br /><br />
    <apex:commandbutton action="{!setCurrTime}" rerender="ajaxresult" value="Display Current Time" /></apex:form>
    </apex:pageBlock><apex:pageBlock title="AjaxData">
    <apex:outputPanel id="ajaxresult" layout="block">
    Result: {!CurrTime}
    </apex:outputPanel>
    </apex:pageBlock>

    </apex:page>

     

  • Parul

    Member
    September 12, 2018 at 4:57 pm

    Hello Suniti,

    AJAX Components are used to dynamically replace the content of a panel tag within a page without replacing the page in the browser window. These tags allow a more seamless, flicker-free user interface. User interactions with a page no longer need to submit/request entire pages, instead, pieces of the page can change as data is entered.
    There are few AJAX components in Salesforce, which supports AJAX functionality. They are:

    •  Action Function
    • Action Poller
    • Action Region
    • Action Status
    • Action Support

    Hope this helps.!

  • shariq

    Member
    September 14, 2018 at 1:52 am

    Hi,

    AJAX is primarily used for partial page updates in Visualforce.  In s-controls, the AJAX toolkit was the soap (XML over HTTP) client that gave you access to the force.com Web Services API.

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos