0

我正在尝试$.get()从 jQuery 拨打电话,但我得到的只是以下错误;

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>

4

1 回答 1

1

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

因为您在完整版本之后加载了苗条版本并覆盖了 $.get

于 2018-12-22T20:55:32.020 回答