What is Javascript Remoting?
Javascript Remoting is a way to call Apex Controller methods from Javascript (written on Visualforce page..). Unlike ActionFunction, Javascript Remoting allows us to call controller methods, without having to transfer the complete viewstate of the page.
As it does not transfer the ViewState, it can also save your Visualforce page from reaching the ViewState limit.
Sample Code
Let’s jump straight to the
sample code which itself should be self explanatory.
Controller Class:
public class TestJSRemoting {
@RemoteAction
public static Account searchAccounts(String name){
account = [SELECT Id, Name, Phone FROM Account WHERE Name = :accountName limit 1];
return account;
}
}
VF page:
<apex:page controller=”TestJSRemoting”>
<script>
</script>
<apex:pageBlock>
<input type=”text” value=””>
<button type=”button”>Search</button>
</apex:pageBlock>
</apex:page>
No comments:
Post a Comment