You need to sign in to do that
Don't have an account?
jkc
How to call a apex class from javascript?
I'm trying to change the timeout value from apex using a button in <apex:actionStatus>
apex class:
javascript:
VF(because apex:commandButton doesn't work in the facet I used <input type:"button">):
apex class:
global class ApexController { public Integer intMergeTimeout {get; set;} public void timeoutMerge(){ //set timeout to 1second intMergeTimeout = 500; } }
javascript:
<apex:includeScript value="/soap/ajax/21.0/connection.js"/> <apex:includeScript value="/soap/ajax/21.0/apex.js"/> <script> function timeout(){ sforce.connection.sessionId = "{!$Api.Session_ID}"; try{ var result = sforce.apex.executeAnonymous("ApexController","timeoutMerge",{}); console.log('Timeout!!'); }catch(e) { alert(e); } } </script>
VF(because apex:commandButton doesn't work in the facet I used <input type:"button">):
<apex:commandButton value="Action" action="{!action}" status="Loading" reRender="pageSecId" timeout="{!intMergeTimeout}"/> <apex:actionStatus id="Loading" > <apex:facet name="start"> <div> <div class="popupBackground" /> <div class="PopupPanel"> <div align="center"> <div class="slds-text-heading--label"> <b>Merging...</b> </div> <div class="slds-button slds-button--brand"> <input type="button" onclick="timeout()" value="Cancel"/> </div> </div> </div> </div> </apex:facet> <apex:facet name="stop"></apex:facet> </apex:actionStatus>
Update your javascript code as below:
Add below code in your VF page: On click of your button, Javascript function get call. This JS function calls actionfunction in VF page which in turn calls your method in controller.
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Javascript Remoting,
use action function to call the method.
Thanks,
Pramodh
Update your javascript code as below:
Add below code in your VF page: On click of your button, Javascript function get call. This JS function calls actionfunction in VF page which in turn calls your method in controller.
-Thanks,
TK
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.