Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

JavaScript Callbacks

If you need to access the response from an asynchronous XMLHttpRequest, provide your request with a callback. The code below retrieves a Contact from CRM by its ID. In the success function, a callback is called, passing it the result from the request (which should be the Contact).

To make use of the result, create a function to call getContact, and evaluate its result:

The callback is called once the response is ready. Notice that the callback function is passed anonymously here as the second parameter of the call to getContact. It is advisable to write this anonymous function separately and give it a name.