There are basically three things required:
- Remote method definition in the controller
- Remote method invocation in the JS.
- Remote method response handler
VF Page:
<apex:page controller="testClass">
<script>
window.onload = function deleteRecord(){
var stringName = 'test';
<apex:page controller="testClass">
<script>
window.onload = function deleteRecord(){
var stringName = 'test';
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction. testClass. check}',
stringName, function(result, event){
if (event.status) {
if(result.length > 0){
if (event.status) {
if(result.length > 0){
//do some logic
}
}
else if(event.type == 'exception'){
alert(event.message + ' '+ event.where);
}
else if(event.type == 'exception'){
alert(event.message + ' '+ event.where);
}
},
{escape: true} }
</script>
</apex:page>
Controller:
Global class testClass{
@RemoteAction
Global void check(String name){
String s= name;
apexPages.addMessages(s);
}
{escape: true} }
</script>
</apex:page>
Controller:
Global class testClass{
@RemoteAction
Global void check(String name){
String s= name;
apexPages.addMessages(s);
}
}
Note:
- If there are multiple parameter required to call a method then pass the parameter in JS method exactly similar which is defined in the controller method. For ex:
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction. testClass. check}',
stringName,stringName1,stringName2, function(result, event){
No comments:
Post a Comment