I am new to Salesforce and I want to achieve what I used to do in html pages. I defined ajaxStart ans Stop event and want it to be called whenever Apex execute it's actionFunction using Ajax. here is my code :

$(document).ajaxStart(function() {
}).ajaxStop(function() {

Please help me! Thanks in advance.

2 Answers 2


The actionFunction has some useful attributes.


The JavaScript invoked when the onbeforedomupdate event occurs--that is, when the AJAX request has been processed, but before the browser's DOM is updated.


The JavaScript invoked when the result of an AJAX update request completes on the client.

So you can define which javascript function should be executed before actionFunction and after:

<apex:actionFunction name="testFunc" 
                     oncomplete="executeAfter()" />

function executeBefore(){

function executeAfter(){
  • That's ok but I want it to be global, I mean I write script at one place and it should work for all the request Commented Jul 5, 2016 at 7:26
  • It is impossible. You can store before/after function in one place but you have to add them to each actionFunction by yourself each time you create a new actionFunction. Commented Jul 5, 2016 at 7:30
  • That's sad.. Salesforce should work on this.. its not good.. Thanks btw Commented Jul 5, 2016 at 7:59
  • Btw the ode I am using fires on every Ajax request normally.. but I am not sure how apex calls Ajax so that it is restricting this function to be called Commented Jul 5, 2016 at 8:01

After Wasting 2 Hours on it, I got a work around not with jquery but with Ajax component. Here is the code :

<apex:actionStatus id="pageStatus">
<apex:facet name="start">
    <apex:outputPanel >
        <img src="/img/loading32.gif" width="25" height="25"  style="z-index:10000;position:fixed;top:-100%; right:-100%; left:-100%; bottom:-100%;margin:auto;" />
        <apex:outputLabel value="Loading..."/>

Now this id 'pageStatus', you can use it any ActionFunction or CommanButton or anything where you can find status property like this :

   <apex:actionFunction name="saveem" action="{!saveem}" rerender="buttonpanel" status="pageStatus"/>

So it is not like global but this single element can work on all the functions on the page.

  • And that's all what you needed? Status? Commented Jul 5, 2016 at 9:34
  • Well I needed to do it by jquery but for the time being its working for me Commented Jul 5, 2016 at 9:38
  • The code which I have mentioned in my question works on every ajax event in the app so it's global but I couldnt find anything like this in apex Commented Jul 5, 2016 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .