Why is $POST coming empty?



  • The problem is: On the button on the page s.php We need to send the data. post by ajax 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.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2