No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Calling a Server-Side Action
A client-side controller is a JavaScript object in object-literal notation containing name-value pairs. Each name corresponds to a client-side action. Its value is the function code associated with the action.
Let’s say that you want to trigger a server-call from a component. The following component contains a button that’s wired to a client-side controller echo action. SimpleServerSideController contains a method that returns a string passed in from the client-side controller.
The following client-side controller includes an echo action that executes a serverEcho method on a server-side controller. The client-side controller sets a callback action that is invoked after the server-side action returns. In this case, the callback function alerts the user with the value returned from the server. action.setParams({ firstName : cmp.get("v.firstName") }); retrieves the firstName attribute from the component and sets the value of the firstName argument on the server-side controller’s serverEcho method.
In the client-side controller, we use the value provider of c to invoke a server-side controller action. This is the same syntax as we use in markup to invoke a client-side controller action. The cmp.get("c.serverEcho") call indicates that we are calling the serverEcho method in the server-side controller. The method name in the server-side controller must match everything after the c. in the client-side call.
Use $A.enqueueAction(action) to add the server-side controller action to the queue of actions to be executed. All actions that are enqueued this way will be run at the end of the event loop. Rather than sending a separate request for each individual action, the framework processes the event chain and executes the action in the queue after batching up related requests. The actions are asynchronous and have callbacks.
Action States
The possible action states are:
- NEW
- The action was created but is not in progress yet
- RUNNING
- The action is in progress
- SUCCESS
- The action executed successfully
- ERROR
- The server returned an error
- ABORTED
- The action was aborted