调试带有运行时错误的jquery ajax脚本

编程入门 行业动态 更新时间:2024-10-10 11:27:19
本文介绍了调试带有运行时错误的jquery ajax脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何从jQuery AJAX接收的脚本中看到运行时错误?

我正在编写一个(自由软件)应用程序(MELT监视器,在GNU / Linux / Debian / x86-64)嵌入其特定的Web服务器。有关详细信息,请参阅此问题。我在提交 d624e22497de ...

我在Linux / Debian / Gnu / x86-64上使用Firefox 38或42,并安装了最新的Firebug。 $ b m使用jQuery的 $。ajax 和脚本:

$。 ajax ({url:/ canvasedit, method:POST, data:{do_fillcanvas:true}, dataType:script,成功:ajaxcanvascript });

正确调用 ajaxcanvascript 显示 console.log ),所以从HTTP的角度来看,AJAX请求已经成功(200 OK)。

然而,当AJAX收到的脚本中存在运行时错误时, do_fillcanvas ,这是一个类似于以下内容的生成的脚本:

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('显示< tt> Sat Nov 7 09:26:39 2015 MET< / tt>'); console.log('dofillcanvas canvedit.c:252 done 09:26:39.11 this =',this);

我的Firebug控制台中没有任何错误信息(或者从Firefox中看不到任何错误消息) / p>

我正在调试的那种运行时错误是eg从 momc_display_canvas (它使用 jcanvas 我不是很熟悉)。

所以,如何从jQuery AJAX收到的脚本中轻松地看到运行时错误?

我在每一处都加入 console.log ,但这样不方便...

解决方案

如果我是正确的,那么在调用ajax到ajax的时候要求处理错误。 jQuery的ajax有一个错误的参数回调函数,您可以使用该回调来处理您的错误。

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

如果你想处理总的错误,你可以使用try catch块来包装整个ajax调用。你})

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...

解决方案

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 })

更多推荐

调试带有运行时错误的jquery ajax脚本

本文发布于:2023-11-23 13:24:03,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   错误   jquery   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!