Answer the question
In order to leave comments, you need to log in
WAMP ajax server not working?
Help! On the server, I created a test folder and placed the index.php files in it, in which the following code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="jquery-3.3.1min.js"></script>
<script src="js.js"></script>
</head>
<body>
<h1>Нажать</h1>
<?php
echo 'Данные приняты - '.$_POST['text'];
?>
</body>
</html>
$(function() {
$('h1').click(function () {
$.ajax({
url: 'index.php', /* Куда пойдет запрос */
method: 'post', /* Метод передачи (post или get) */
/* Тип данных в ответе (xml, json, script, html). */
data: {text: 5}, /* Параметры передаваемые в запросе. */
success: function(data){ /* функция которая будет выполнена после успешного запроса. */
console.log(data); /* В переменной data содержится ответ от index.php. */
}
});
});
});
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="jquery-3.3.1min.js"></script>
<script src="js.js"></script>
</head>
<body>
<h1>Нажать</h1>
Данные приняты - 5
</body>
</html>
Answer the question
In order to leave comments, you need to log in
Errors need to be read, they contain a detailed description of the problem. Let's break this error into pieces:
Notice: Undefined index: text in D:\Wamp\www\tost\index.php on line 12
Notice:
- an error of the notice level, in fact, not even an error, but a notification. Undefined index: text
- index "text" does not exist, this means that you are trying to access the index "text" of some array, but such an index (array element) does not exist. D:\Wamp\www\tost\index.php on line 12
- and here is the specific place in your code where this error occurred. This is line 12, it contains the following code: echo 'Данные приняты - '.$_POST['text'];
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
<script src="jquery-3.3.1min.js"></script>
<script src="js.js"></script>
</head>
<body>
<h1>Нажать</h1>
<?php
if (isset($_POST['text'])) {
echo 'Данные приняты - ' . htmlspecialchars($_POST['text']);
} ?>
</body>
</html>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question