调试带有运行时错误的jquery ajax脚本 [英] debugging jquery ajax script with runtime error
问题描述
如何从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脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!