Debugging jquery ajax script with runtime error

How can I see the runtime error from the resulting jQuery AJAX script?

I am encoding an application (free software) (MELT monitor, on GNU / Linux / Debian / x86-64) that implements its specific web server. See this question for more details. I am in fixing d624e22497de ...

I am using Firefox 38 or 42 on Linux / Debian / Gnu / x86-64 with recent Firebug.

I am using jQuery $.ajax with a script:

 $.ajax ({url: "/canvasedit", method: "POST", data: {"do_fillcanvas": true}, dataType: "script", success: ajaxcanvascript }); 

ajaxcanvascript is correctly called (and console.log displayed), so from an HTTP point of view, the AJAX request succeeded (200 OK).

However, if AJAX do_fillcanvas script error on do_fillcanvas , which is a generated script error at runtime, similar to:

  console.log('dofillcanvas canvedit.c:206 siz 1; this=', this, ' momc_display_canvas=',momc_display_canvas); momc_display_canvas('09:26:39',[ momc_top_entry(momc_item_ref('notice'), momc_node(momc_item_ref('comment'), [ momc_string("some simple notice"), momc_node(momc_item_ref('web_state'), [ momc_int(2)]), momc_item_val('hashset'), momc_set([ momc_item_ref('canvasedit'), momc_item_ref('microedit'), momc_item_ref('the_agenda')]) , momc_tuple([ momc_item_ref('web_session'), momc_nil_ref(), momc_item_ref('the_system')]) ]))]); console.log('dofillcanvas canvedit.c:239 this=', this); addupdatehtml('displayed <tt>Sat Nov 7 09:26:39 2015 MET</tt>'); console.log('dofillcanvas canvedit.c:252 done 09:26:39.11 this=', this); 

I have no error message in my Firebug console (or nothing is visible from Firefox).

The kind of runtime error that I am debugging, for example, some undefined method called deep from momc_display_canvas (which uses jcanvas , which I am not very familiar with).

So, how easy is it to see the runtime error from jQuery AJAX received by the script?

I add console.log everywhere, but it is not convenient ...

+6
source share
1 answer

If I am right, you are asking to handle the error when calling ajax to complete ajax. Jquery ajax has a parameter callback function for error, you can use this callback to handle your error.

 $.ajax({ ... error: function(error){ console.log(error); } ... }) 

If you want to handle a generic error, you can use the packaging of a try catch block around a generic ajax call. Hope this helps you})

+1
source

All Articles