Skip to content

Instantly share code, notes, and snippets.

@zokito
Forked from futurehope/RemoteController.cls
Created October 25, 2013 13:57
Show Gist options
  • Save zokito/7155111 to your computer and use it in GitHub Desktop.
Save zokito/7155111 to your computer and use it in GitHub Desktop.
global class RemoteController {
@RemoteAction
global static String test0Str(){
return '0 arguments';
}
@RemoteAction
global static String test1Str(String str){
return str;
}
@RemoteAction
global static String test2Str(String str1,String str2){
return str1+ ' ' + str2;
}
}
<apex:page controller="RemoteController" >
<script>
function handleReturn(result, event) {
if (event.status) {
document.getElementById("output").innerHTML = result + ', ' + document.getElementById("output").innerHTML;
} else if (event.type === 'exception') {
document.getElementById("output").innerHTML = event.message;
} else {
document.getElementById("output").innerHTML = event.message;
}
}
</script>
<div id="output" />
<form >
<div>
<input value="summer12 0 params" onclick="Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.RemoteController.test0Str}', handleReturn,{escape: true})" type="button" />
<input value="spring12 0 params" onclick="RemoteController.test0Str( handleReturn,{escape: true})" type="button" />
</div>
<div>
<input value="summer12 1 params" onclick="Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.RemoteController.test1Str}','1 argument', handleReturn,{escape: true})" type="button" />
<input value="spring12 1 params" onclick="RemoteController.test1Str('1 argument', handleReturn,{escape: true})" type="button" />
</div>
<div>
<input value="summer12 2 params" onclick="Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.RemoteController.test2Str}','2','arguments', handleReturn,{escape: true})" type="button" />
<input value="spring12 2 params" onclick="RemoteController.test2Str('2','arguments', handleReturn,{escape: true})" type="button" />
</div>
</form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment