Debugging JavaScript Remoting

Debugging pages that use JavaScript remoting requires you to debug Visualforce, Apex, and JavaScript.

Keep your JavaScript console open during development when using JavaScript remoting. Errors and exceptions encountered by JavaScript remoting are logged to the JavaScript console, if enabled, and are otherwise silently ignored.

Important

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.
1<script type="text/javascript">
2function getRemoteAccount() {
3    var accountName = document.getElementById('acctSearch').value;
4
5    Visualforce.remoting.Manager.invokeAction(
6        '{!$RemoteAction.MyController.getAccount}', 
7        accountName, 
8        function(result, event){
9            if (event.status) {
10                document.getElementById('acctId').innerHTML = result.Id
11                document.getElementById('acctName').innerHTML = result.Name;
12            } else if (event.type === 'exception') {
13                document.getElementById("responseErrors").innerHTML = 
14                    event.message + "<br/>\n<pre>" + event.where + "</pre>";
15            } else {
16                document.getElementById("responseErrors").innerHTML = event.message;
17            }
18        }
19    );
20}
21</script>