admin管理员组

文章数量:1134246

I have this script:

<script>
$(document).ready(function () {
    $("#changeResumeStatus").click(function () {
        $.get("{% url 'main:changeResumeStatus' %}", function (data) {
            if (data['message'] == 'hidden') {
                $("#resumeStatus").text("скрыто");
            } else {
                $("#resumeStatus").text("опубликовано");
            }
        }, "json");
    });
});
</script>

I receive the following error in my Google Chrome console:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

I am using jQuery v1.10.2 and #changeResumeStatus is a <span>.

What's wrong with my script?

I have this script:

<script>
$(document).ready(function () {
    $("#changeResumeStatus").click(function () {
        $.get("{% url 'main:changeResumeStatus' %}", function (data) {
            if (data['message'] == 'hidden') {
                $("#resumeStatus").text("скрыто");
            } else {
                $("#resumeStatus").text("опубликовано");
            }
        }, "json");
    });
});
</script>

I receive the following error in my Google Chrome console:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

I am using jQuery v1.10.2 and #changeResumeStatus is a <span>.

What's wrong with my script?

Share Improve this question edited Dec 23, 2013 at 22:26 Alex Parakhnevich asked Nov 18, 2013 at 10:12 Alex ParakhnevichAlex Parakhnevich 5,1724 gold badges28 silver badges30 bronze badges 5
  • 19 I think that's not an error, but merely a warning - this one can be safely ignored. – Qantas 94 Heavy Commented Nov 18, 2013 at 10:14
  • 32 This warning is following lastest chrome update, don't worry – A. Wolff Commented Nov 18, 2013 at 10:15
  • 2 You should look into escaping non-ascii strings. – Gleno Commented Nov 21, 2013 at 9:12
  • @Gleno what for? my templates work completely fine in utf-8 – Alex Parakhnevich Commented Nov 21, 2013 at 9:32
  • 4 @AlexParakhnevich There's no single compelling reason to do so, but a few minor ones that creep up from time to time. My reaction was instinctive rather than well thought out, to be honest. In projects I'm working on right now, there's a guideline to not use non-ascii chars in literals, which I instituted in the past, because some external tools (typescript compiler) choked on such input. It works well enough in most cases, but sometimes eats up a lot of developer time when things go wrong. Anyway, .empty().append("text") is better expressed as .text("text"). – Gleno Commented Nov 21, 2013 at 9:50
Add a comment  | 

7 Answers 7

Reset to default 204

This is only a warning: your code still works, but probably won't work in the future as the method is deprecated. See the relevant source of Chromium and corresponding patch.

This has already been recognised and fixed in jQuery 1.11 (see here and here).

Just for other's reference, I just received this and found it was due to AngularJS. It's for backwards compatibility:

if (!event.preventDefault) {
    event.preventDefault = function() {
        event.returnValue = false; //ie
    };
}

If you using Bootstrap:

The current version of Bootstrap (3.0.2) (with jQuery 1.10.2 & Chrome) seems to generate this warning as well.

(It does so on Twitter too, BTW.)

Update

The current version of Bootstrap (3.1.0) no longer seems to generate this warning.

That's your jQuery API problem, not your script. There is not much to worry about.

This is a warning related to the fact that most JavaScript frameworks (jQuery, Angular, YUI, Bootstrap...) offer backward support for old-nasty-most-hated Internet Explorer starting from IE8 down to IE6 :/

One day that backward compatibility support will be dropped (for IE8/7/6 since IE9 deals with it), and you will no more see this warning (and other IEish bugs)..

It's a question of time (now IE8 has 10% worldwide share, once it reaches 1% it is DEAD), meanwhile, just ignore the warning and stay zen :)

I found that using the latest version will fix this problem:
http://code.jquery.com/jquery-git.js

I saw this warning on many websites. Also, I saw that YUI 3 library also gives the same warning. It's a warning generated from the library (whether is it jQuery or YUI).

本文标签: