Newer Version Available
Debugging JavaScript Remoting
Debugging pages that use JavaScript remoting requires you to debug
Visualforce, Apex, and
JavaScript.
When a @RemoteAction method throws an exception due to a programming error or other failure, the Apex stack trace is returned to the browser within the event object. Inspect the stack trace in a JavaScript debugger console or use it in the error handling of your response callback function.
Here’s a callback function that simply displays the stack trace when there’s an
exception.
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17<script type="text/javascript">
18function getRemoteAccount() {
19 var accountName = document.getElementById('acctSearch').value;
20
21 Visualforce.remoting.Manager.invokeAction(
22 '{!$RemoteAction.MyController.getAccount}',
23 accountName,
24 function(result, event){
25 if (event.status) {
26 document.getElementById('acctId').innerHTML = result.Id
27 document.getElementById('acctName').innerHTML = result.Name;
28 } else if (event.type === 'exception') {
29 document.getElementById("responseErrors").innerHTML =
30 event.message + "<br/>\n<pre>" + event.where + "</pre>";
31 } else {
32 document.getElementById("responseErrors").innerHTML = event.message;
33 }
34 }
35 );
36}
37</script>