【问题标题】:$.getJSON uncaught reference error $ is not defined [duplicate]$.getJSON 未捕获的引用错误 $ 未定义 [重复]
【发布时间】:2021-05-26 20:01:11
【问题描述】:

有人知道我该如何修复此代码吗?它在第 5 行给了我错误,在 $.getJSON 中,它说“未捕获的引用错误:$ 未定义”

    <link rel="stylesheet" href="style.css">
<script>
var url = "https://api.minetools.eu/ping/mc.hypixel.net/25565";
 
$.getJSON(url, function(r) {
    //data is the JSON string
 if(r.error){
    $('#resto').html('Server Offline');
   return false;
 }
var pl = '';
 if(r.players.sample.length > 0 ){ pl = '<br>OP: '+r.players.sample[0].name;  } 
  $('#resto').html(r.description.replace(/§(.+?)/gi, '')+'<br><b>Players Online:</b> '+r.players.online+pl);
 $('#favicon').attr('src', r.favicon);
});
var rest = resto
</script>
<div class="card"> <div class="icon"><img src="https://www.joomla.it/images/immagini/sampledata/Joomla-flat-logo-en.png" id="favicon"></div><div class="header">
  <div class="image"> <img src="https://pbs.twimg.com/media/C2bx8KGWQAEORsE.jpg" alt="" /> </div>
  <h2>mc.hypixel.net</h2>
  </div>
  <div id="rest">Loading ...</div>
</div>

【问题讨论】:

  • "$ is not defined" 是您忘记包含 jQuery 库时显示的典型错误

标签: javascript minecraft getjson


【解决方案1】:

在脚本之前添加 jquery 库

<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>

【讨论】:

  • 危险 jQuery 1.x 已经过时(并且已经过了很多年)。它不受支持、不接收安全更新并且存在已知的安全漏洞。
  • 更新版本@Quentin
猜你喜欢
  • 1970-01-01
  • 2020-09-17
  • 1970-01-01
  • 2018-10-23
  • 2013-10-27
  • 2023-03-04
  • 1970-01-01
  • 2011-09-25
  • 2021-11-01
相关资源
最近更新 更多