Why is $POST coming empty?
-
The problem is: On the button on the page
s.php
We need to send the data.post
byajax
e.g."text: 'Текст'"
the developer's panel has a positive response. Requested the program. POSTMAN The following answer comes:"Текст"
♪ But variable_POST()
Always empty, what am I doing wrong?html
<body> <button id="sub">Отправить!</button> </body>
js
$(document).ready(function () { $("#sub").click(function () { $.ajax({ url: 's.php', method: 'post', dataType: 'html', data: {text: 'Текст'}, success: function(data){ alert(data); } }); }); });
php
<?php if(isset($_POST['text'])){ echo $_POST['text']; } ?>
-
$(document).ready(function () { $("#sub").click(function () { $.ajax({ url: 's.php', method: 'post', dataType: 'JSON', data: {text: 'Текст'}, success: function(data){ alert(data); } }); }); });
Try this instead of dataType: HTML on dataType.