Javascript Ajax 的控制台错误:ReferenceError:$ 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26273833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-22 22:39:27  来源:igfitidea点击:

Console Error with Ajax: ReferenceError: $ is not defined

javascriptajaxweb

提问by moritz.muecke

i have a problem with a little script on my html page. It's just a function which should be called by an onclick method in an a tag. It dont works. Everytime i click on the link in the browser the console says "ReferenceError: $ is not defined" and points on the third line of the code below.

我的 html 页面上的一个小脚本有问题。它只是一个应该由 a 标签中的 onclick 方法调用的函数。它不起作用。每次我点击浏览器中的链接时,控制台都会显示“ReferenceError: $ is not defined”并指向下面代码的第三行。

<script>
    function del(urlToDelete) {
        $.ajax({
            url: urlToDelete,
            type: 'DELETE',
            success: function(results) {
                location.reload();
            }
        });
    }
</script>

回答by Arindam Nayak

You need to include jquery library for that.Like this. You need to include this 1st, then write $.ajaxto execute.

您需要为此包含 jquery 库。像这样。您需要包含第一个,然后写入$.ajax执行。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

回答by LiamWilson94

It looks like the jQuery libraries have not been included within your project.

看起来您的项目中尚未包含 jQuery 库。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

回答by Sourabh Sinha

The above answers use http version,which might not be allowed at production ,alternatively use:

上面的答案使用 http 版本,在生产中可能不允许,或者使用:

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

or visit: https://code.jquery.com/

或访问:https: //code.jquery.com/