3

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() {
        alert("hi");
}).ajaxStop(function() {
      alert("hello");
});

Please help me! Thanks in advance.

2 Answers 2

2

The actionFunction has some useful attributes.

onbeforedomupdate:

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.

oncomplete:

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" 
                     onbeforedomupdate="executeBefore();"
                     oncomplete="executeAfter()" />

<script>
function executeBefore(){
    ...
}

function executeAfter(){
    ...
}
</script>
4
  • 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
0

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..."/>
    </apex:outputPanel>            
</apex:facet>
</apex:actionStatus>

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.

3
  • 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 .