I keep getting the error “Object #<Object> h

2019-07-31 05:58发布

I am using jQuery 1.8 and have been getting this error on some pages when I use the .on() function. Other pages, seemingly doing the exact same thing -- attaching triggers to dynamically created elements, that I use do not generate this error:

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

JS:

$(document).ready(function(){
    $(document).on("click","button.pagebutton",function() {
        $("div#pagesforreview").hide();
        jsD=Date();
        jsP=$(this).html();
        $("div#externpage").load("prexternpage.php",{d:jsD,p:jsP},function() {
            $("div#externpage").show();
            $("div#pageactions").show();
            jsNc=1;
            $("div#pagecomments").load("praddcomment.php",{d:jsD,nc:jsNc},function() {
            $("div#pagecomments").show();
            });
        });
    });
});

All dynamically generated 'pagebutton' buttons, don't trigger. And the error shows up. If I use the .live() method that is deprecated, no problems. But I prefer to use the proper new 1.8 non-deprecated method, if possible?

2条回答
我想做一个坏孩纸
2楼-- · 2019-07-31 06:30

I figured out that my header file was loading the jquery library (v. 1.6) from my production server not my development server (v. 1.8)... thus creating the problem. D'oh. Thanks for the comments.

查看更多
混吃等死
3楼-- · 2019-07-31 06:32

instead this $(document).ready(function(){ in the first line write this : jQuery(document).ready(function($){ it worked for me.

查看更多
登录 后发表回答