PathJS - 未捕获TypeError:对象#<object>没有方法'default'(匿名函数)</object>

时间:2011-06-07 01:05:03

标签: jquery jquery-plugins path.js

我正在尝试使用PathJS,并在控制台中收到以下错误:

Uncaught TypeError: Object #<Object> has no method 'default'

(匿名函数)

我正在使用以下教程:http://mtrpcic.net/2011/02/fragment-uris-theyre-not-as-bad-as-you-think-really/

使用插件:https://github.com/mtrpcic/pathjs

我的应用程序加载jQuery然后加载PathJS插件,然后加载app.js中的代码:

$("a").live("click", function(event){
    var href = $(this).attr("href");
    if(href[0] == "/"){
        event.preventDefault();
        window.location.hash = "#!" + href;
    }
});

Path.default(function(){
    $.get(window.location.hash.replace("#!", ""), function(data){
        $("#contents").html(data);
    });
});
Path.listen();

为什么我收到错误的任何想法?

1 个答案:

答案 0 :(得分:1)

你的Path.listen()应该像这样包裹起来:

$(document).ready(function() {
    Path.listen();
)};

如果您已经这样做了(从上面的代码中看不出来,但您可能没有包含该部分)那么我会质疑您的Path.default代码。我没有看到文档中的默认路径。但是,有一个Path.root,但您仍然需要提供一条路线。我想知道是否可能在某些时候从代码中删除了它,正如我在你提到的教程中看到的那样。