---
schema_version: "1"
id: 6e068353bcd71ade7ab17d2016e480e48afa70c9a22cef131b75c6338bf15cd1
title: Adding JavaScript Remoting to a Visualforce Page
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/javascript/pages-js-remoting-invoking.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-js-remoting-invoking.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: bb688d43f04178d8201bdbd3786c59e4c8b0333c1545ec44229936cedae8952c
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Adding JavaScript Remoting to a Visualforce Page

To use JavaScript remoting in a Visualforce page, add the request as a JavaScript function call.

Add the Apex class as a custom controller or a controller extension to your page.

```apex
<apex:page controller="MyController" extension="MyExtension">
```

**warning:** Adding a controller or controller extension grants access to all `@RemoteAction` methods in that Apex class, even if those methods aren’t used in the page. Anyone who can view the page can execute all `@RemoteAction` methods and provide fake or malicious data to the controller.

Then, add the request as a JavaScript function call. A simple JavaScript remoting invocation takes the following form.

```javascript
[namespace.]MyController.method(
    [parameters...,]
    callbackFunction,
    [configuration]
);
```

| Element                       | Description                                                                                                                                                                                                                   |
| ----------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `namespace`                   | The namespace of the controller class. The namespace element is required if your organization has a namespace defined, or if the class comes from an installed package.                                                       |
| `MyController`, `MyExtension` | The name of your Apex controller or extension.                                                                                                                                                                                |
| `method`                      | The name of the Apex method you’re calling.                                                                                                                                                                                   |
| `parameters`                  | A comma-separated list of parameters that your method takes.                                                                                                                                                                  |
| `callbackFunction`            | The name of the JavaScript function that handles 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 element to change the behavior of a remoting call, such as whether or not to escape the Apex method’s response.                                             |

The remote method call executes synchronously, but it doesn’t wait for the response to return. When the response returns, the callback function handles it asynchronously. See [Handling the Remote Response](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-js-remoting-handling-response.md#handling-the-remote-response) for details.
