No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
JavaScript Remoting
Use JavaScript remoting in Visualforce to call methods in Apex controllers from JavaScript. Create pages with complex, dynamic behavior that isn’t possible with the standard Visualforce AJAX components.
JavaScript remoting has three parts:
- The remote method invocation you add to the Visualforce page, written in JavaScript.
- The remote method definition in your Apex controller class. This method definition is written in Apex, but there are few differences from normal action methods.
- The response handler callback function you add to or include in your Visualforce page, written in JavaScript.
In your controller, your Apex method declaration is preceded with the @RemoteAction annotation like this:
1@RemoteAction
2global static String getItemId(String objectName) { ... }To use JavaScript remoting in a Visualforce page, add the request as a JavaScript invocation with the following
form:
1[namespace.]controller.method(
2 [parameters...,]
3 callbackFunction,
4 [configuration]
5);- namespace is the namespace of the controller class. This is required if your organization has a namespace defined, or if the class comes from an installed package.
- controller is the name of your Apex controller.
- method is the name of the Apex method you’re calling.
- parameters is the comma-separated list of parameters that your method takes.
- callbackFunction is the name of the JavaScript function that will handle the response from the controller. You can also declare an anonymous function inline. callbackFunction receives the status of the method call and the result as parameters.
- configuration configures the handling of the remote call and response. Use this to change the behavior of a remoting call, such as whether or not to escape the Apex method’s response.
For more information, see “JavaScript Remoting for Apex Controllers” in the Visualforce Developer's Guide.