繁体   English   中英

jQuery AJAX函数未定义

[英]jQuery AJAX functions not defined

我正在尝试从jQuery进行$.get()调用,但是我得到的只是以下错误;

Uncaught TypeError: $.get is not a function
    at HTMLDocument.<anonymous> (client.js:12)
    at l (jquery.min.js:2)
    at c (jquery.min.js:2)

我到处搜寻,似乎找不到答案。 我正在使用Google CDN导入jQuery。 https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js

最小的例子

 $(document).ready(function() { jQuery.get('echo/authstatus', function(data) { console.log(data); }); }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> 

完整片段

 let denied = `<div class="alert alert-danger" role="alert"> <strong>Access Denied!</strong> Please check your username and password, then try again. </div>`; let granted = `<div class="alert alert-success" role="alert"> <strong>Access Granted!</strong> Welcome, please wait while we redirect you. </div>`; let disabled = `<div class="alert alert-warning" role="alert"> <strong>Authentication disabled!</strong> Sorry, we have temporarily disabled authentication! </div>`; $(document).ready(function() { jQuery.get('echo/authstatus', function(data) { console.log(data); }); }); 
 <!DOCTYPE html> <html lang="en"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet"> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous"> <meta charset="UTF-8"> <title>Echo Login System</title> <style> .ubuntu { font-family: 'Ubuntu', sans-serif; } </style> <script src="client.js"></script> </head> <body class="bg-dark"> <div class="jumbotron bg-dark"> <h1 class="display-4 text-info">Echo Login System</h1> <p class="lead text-white-50">A JavaScript login system, by Eton.</p> <hr class="my-4 bg-info"> </div> <div class="container" id="display"> </div> <div class="container shadow" style="width:24rem"> <h5 class="ubuntu text-info" style="padding-top: 1%">Authentication Required!</h5> <form> <div class="form-group"> <input type="text" class="form-control ubuntu" id="username" placeholder="Username"> </div> <div class="form-group"> <input type="password" class="form-control ubuntu" id="password" placeholder="Password"> </div> <button id="login" class="btn btn-info" style="margin-top:1%;">Login</button> </form> <br> </div> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script> </body> </html> 

您应该删除底部<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

当您在完整版之后加载精简版并覆盖$ .get时

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM