Функции jQuery AJAX не определены - PullRequest
0 голосов
/ 22 декабря 2018

Я пытаюсь сделать $.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)

Я искал все и не могу найти ответ,Я импортирую jQuery, используя Google CDN.(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>

1 Ответ

0 голосов
/ 22 декабря 2018

Вы должны удалить первый тег сценария внизу <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

Поскольку у вас есть уменьшенная версия, загружающаяся после полной версии и переопределяющая $ .get

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...