Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

debugging jquery ajax script with runtime error

How can I see a runtime error from a jQuery AJAX received script?

I'm coding a (free software) application (the MELT monitor, on GNU/Linux/Debian/x86-64) which embeds its specific web server. See this question for details. I'm at commit d624e22497de...

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

I'm using a jQuery's $.ajax with a script:

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

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

However, when there is a runtime error in the AJAX received script by do_fillcanvas, which is a generated script similar to something like:

     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've got no error message in my Firebug console (or nothing easily visible from Firefox).

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

So, how to easily see runtime error from a jQuery AJAX received script?

I'm adding console.log everywhere, but that is not convenient...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If I am right then you are asking to handle error while calling the ajax to the ajax complete. The jquery ajax has a parameter callback function for error, you can use that callback to handle your error.

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

If you want to handle total error you can use try catch block wrapping around the total ajax call.Hope this will help you })


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...