$.getJSON 未捕获引用错误 $ is not defined
$.getJSON uncaught reference error $ is not defined
有人知道我该如何修复这段代码吗?它在第 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>
在脚本前添加 jquery 库
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>
有人知道我该如何修复这段代码吗?它在第 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>
在脚本前添加 jquery 库
<script src="http://code.jquery.com/jquery-3.5.1.min.js"></script>