调试阿贾克斯code与萤火虫 [英] Debugging Ajax code with Firebug

查看:105
本文介绍了调试阿贾克斯code与萤火虫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一对夫妇的调试code问题退换的Ajax调用 - 特别是,在返回的JSON(错误不会被困在Firefox)的函数 - 最多的地步,我开始调试这些问题互联网浏览器(我认为这是一个Firefox的相关问题,为的Venkman不检测这些错误或者)你知道有什么方法可以调试code以JSON返回从一个Ajax调用?


I've a couple of problems debugging code returned in an Ajax call - specifically, a function returned in json (errors don't get trapped in Firefox) - up to the point where I started debugging these problems in Internet Explorer (I think it's a firefox related problem, as Venkman doesn't detects those errors either) Do you know of any way to debug code returned in json from an Ajax call?


EDITED 03/04/2009 15:05


EDITED 03/04/2009 15:05


感谢所有您的答复,但我想我没有解释自己不够好。我知道足够萤火虫做基本调试,但是当我去拿点code在Ajax调用,有一个问题,是我的问题发生。比方说,我们有以下的HTML文件(你需要的原型在同一文件夹,使其正常工作):

Thanks to all for your responses, but I think I didn't explain myself well enough. I know enough of Firebug to do basic debugging, but my problem happens when I fetch some code in an Ajax call that has a problem with it. Let's say we have the following HTML file (you'll need prototype in the same folder to make it work correctly):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript" src="prototype.js"></script>
</head>
<body>
<script>
function ajaxErrorTest()
{
    new Ajax.Request('data.json', {
           'method': 'get',
           'onSuccess': function(data){
           if(data.responseJSON.func)
           data.responseJSON.func();}});
}
</script>
<input type="button" value="test" onclick="ajaxErrorTest();" />
</body>
</html>

和然后,该data.json文件的内容是这样的:

and then, the contents of the data.json file is this:

{'func':function(){console.log('loaded...');alert('hey');}}

如果您加载在浏览器页面,点击测试按钮(一切顺利的话),你会得到一些控制台,并说'嗨'一个警告框。现在data.json文件改成这样:

If you load the page in a browser and click the 'Test' button (and everything goes well) you'll get something in the console, and an alert box that says 'hey'. Now change the data.json file to this:

{'func':function(){console.log('loaded...');alerts('hey');}}

...,然后再次单击测试按钮(无需重新加载页面;-) 你得到的控制台线路,但没有提示框...并没有错误!这是种错误,我试图调试。

...and click the 'Test' button again (no need to reload the page ;-) You get the console line, but no alert box... and no errors!!! this is the kind of errors I'm trying to debug.

推荐答案

尝试单击控制台面板上(这是一个选项卡),并启用它。你会发现,任何HTTP请求将连同它们所包含的任何信息被捕获。我用这个,以查看存储在请求以及任何错误(500/404 /等)的任何JSON。

Try clicking on the "Console" panel (it's a tab) and enabling it. You will find that any HTTP requests will be caught along with any information that they contain. I use this in order to view any JSON stored in the request as well as any errors (500/404/etc).

另外要注意,你必须启用每个域的基础控制台面板。通常有三种子选项卡:头,POST和响应。我通常很使用post /响应选项卡的位,当我调试我的AJAX。

Also be aware that you have to enable the console panel on a per-domain basis. There are usually three subtabs: headers, post, and response. I usually use the post/response tabs quite a bit when I'm debugging my AJAX.

这篇关于调试阿贾克斯code与萤火虫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆