jQuery ajaxOptions -error工作,为什么不成功?

时间:2010-10-19 19:22:17

标签: jquery jquery-ui jquery-ui-tabs

我正在使用jQuery UI标签,并使用示例代码:

$(function() {
    $("#tabs").tabs({
        ajaxOptions: {
            error: function(xhr, status, index, anchor) {
                $(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
            }
        }
    });
});

这里的问题是我希望捕获一个AJAX成功,以便在将数据注入DIV时获取JSON对象......

但这不起作用

$(function() {
        $("#tabs").tabs({
            ajaxOptions: {
                success: function(xhr, status, index, anchor) {
                    alert('hello world');
                },
                error: function(xhr, status, index, anchor) {
                    $(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
                }
            }
        });
    });

想法?

由于

3 个答案:

答案 0 :(得分:0)

如果你复制&粘贴后,您在“错误”之前的成功函数后缺少逗号。

答案 1 :(得分:0)

您在关闭成功功能之前是否缺少逗号或是否为拼写错误?

ajaxOptions: {
            success: function(xhr, status, index, anchor) {
                alert('hello world');
            },
            error: function(xhr, status, index, anchor) {
                $(anchor.hash).html("Couldn't load this tab. We'll try to fix this as soon as possible. If this wouldn't be a demo.");
            }
        }
编辑:对不起,迟到的回答

答案 2 :(得分:0)

删除了ajaxOptions和缓存选项;使用beforeLoad事件

(#7147)已删除ajaxOptions和cache选项以支持beforeLoad事件。有关完整详细信息,请参阅1.9弃用通知。