最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery.Deferred exception: $(...).error is not a function, TypeError $(...).error is not a function - Stack Overflo

programmeradmin4浏览0评论

I've searched alot to find the answer, but on every page or every question the problem is either the Person didnt include the jQuery files proberly or they were naming something wrong. I tried to use different jQuery CDNs, but obviously the same error came. I even deleted my whole script to look if there is a conflict with the code. Strange thing is, only the .error() handler gets this error. Every other handler works fine. If i call .error() on an other element, it spits out the same error.

HTML:

<img class="prev_img" src="img/no_image.png" alt="Vorschau Bild" width="250px" height="160px">

JS

<script
  src=".4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>


<script type="text/javascript"> 
    $(document).ready(function(){
        $("img").error(function(){
            console.log("Error");
        });
    });
</script>

I really don't know what the Problem could be. I restarted my XAMPP multiple times in Hope its messing something up with the file inclution. But it seems that everything works fine.

I'm glad if i could get some help.

Greetings

EDIT:

I've tried using

$(document).ready(function(){
        $("img").on("error", function(){
            console.log("Error");
        });
    });

but even though in the console i get a GET 404 not found error, the error handler doesnt do anything.

I've searched alot to find the answer, but on every page or every question the problem is either the Person didnt include the jQuery files proberly or they were naming something wrong. I tried to use different jQuery CDNs, but obviously the same error came. I even deleted my whole script to look if there is a conflict with the code. Strange thing is, only the .error() handler gets this error. Every other handler works fine. If i call .error() on an other element, it spits out the same error.

HTML:

<img class="prev_img" src="img/no_image.png" alt="Vorschau Bild" width="250px" height="160px">

JS

<script
  src="https://code.jquery./jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>


<script type="text/javascript"> 
    $(document).ready(function(){
        $("img").error(function(){
            console.log("Error");
        });
    });
</script>

I really don't know what the Problem could be. I restarted my XAMPP multiple times in Hope its messing something up with the file inclution. But it seems that everything works fine.

I'm glad if i could get some help.

Greetings

EDIT:

I've tried using

$(document).ready(function(){
        $("img").on("error", function(){
            console.log("Error");
        });
    });

but even though in the console i get a GET 404 not found error, the error handler doesnt do anything.

Share Improve this question edited Dec 16, 2019 at 15:44 Niggo123999 asked Dec 16, 2019 at 15:35 Niggo123999Niggo123999 371 silver badge4 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 6

Per the documentation, .error() was deprecated in 1.8 and removed in 3.0.

Use .on("error", function() { ... }) instead.

$("img").on("error", function() {
  console.log("Error");
});
<script src="https://cdnjs.cloudflare./ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<img src="">

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论