本文介绍了Firefox在AJAX“线程"上没有显示javascript错误吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数 test_fn ,它被称为两种方式:

I have a function test_fn that's called two ways:

(a)通过按钮的 onclick 属性;或(b)来自jQuery AJAX调用的成功函数,例如:

(a) From an onclick attribute of a button; or (b) from the success function of a jQuery AJAX call, like this:

$.ajax({
    type:  'POST',
    ...
    success: function(data) {
        test_fn();
    }
});

我注意到我的Firefox(Linux上为3.6.17)错误控制台似乎没有向我显示在AJAX成功函数调用的代码中出现的任何 javascript错误.像往常一样,它确实会在由GUI动作运行的代码中显示错误.

I've noticed that my Firefox (3.6.17 on Linux) Error Console doesn't seem to show me any javascript errors that arise in code called by the AJAX success function. Whereas it does show errors, as usual, in code that's run by a GUI action.

例如,如果我的测试函数 test_fn 定义如下:

For example, if I have my test function test_fn defined as follows:

function test_fn() {
    blah
}

通过单击按钮调用 test_fn 时,我会在错误控制台上看到报告的明显javascript错误,但是当我的代码执行(成功的)AJAX调用并调用 test_fn 这样.

I'll see the obvious javascript error reported on the Error Console when test_fn is invoked via a click on the button, but NOT when my code does the (successful) AJAX call and calls test_fn that way.

我环顾了网上,却没有看到类似"AJAX'线程'不记录其javascript错误"之类的内容.我的许多JavaScript都是在AJAX回调中执行的...我想知道这种行为是否已潜入某个地方/以某种方式.我对此有些不知所措;当一个人的Java脚本无声地失败时,很难在没有错误消息或行号的情况下进行跟踪.

I've looked around the web and haven't seen anything along the lines of "AJAX 'threads' don't log their javascript errors" or anything like that. A lot of my javascript is executed within an AJAX callback ... I'm wondering if this behaviour has sneaked in somewhere/somehow. I'm a bit rattled by it; when one's Javascript silently fails it's hard to track down where without an error message or line number.

任何人都可以提供任何帮助或建议吗?谢谢.

Can anyone offer any help or advice? Thanks.

推荐答案

您是否尝试过:

$.ajax({
    type:  'POST',
    ...
    success: function(data) {
        test_fn();
    },
    error: function(jqXHR, textStatus, errorThrown){
       // Aw Snap... Check textStatus maybe?
    }
});

这篇关于Firefox在AJAX“线程"上没有显示javascript错误吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:44