JQuery / AJAX脚本不发送数据到php文件?

I am making a question/status posting system using JQuery and Ajax however an error is being displayed "Notice: Undefined index: status in C:\xampp\htdocs\deadline\data.php on line 5" which is my line of code "$var = $_POST['status']; "

My system works as you have to log in to post a question(using sessions) BUT the issue is with my JQuery/AJAX script as the data that I have on homepage.php is not being sent to data.php (from my understanding which is why my index 'status' is undefined).

MY CODE

    <?php
    include("connection.php");

    session_start();

    if(isset($_SESSION['user_id']) && $_SESSION['user_id'] != "") {
            
        }

          else {

            header("location:login.php");
        }

    $sid = $_SESSION['user_id'];

    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

    $sql = "SELECT * FROM `users` WHERE id='{$sid}'";

     $query = $conn->query($sql);

    $result = $query->fetch_assoc();

    $fname = $result['fname'];

    $lname = $result['lname'];

    $time = time();

    ?>

    <html>
    <head>

    <script type="text/javascript" src="jquery.js"></script>

    <script type="text/javascript">

    //daddy code
    $ (document).ready(function() {

    //mama code
    $("button#postbutton").click(function() {
    //children code
    var status = $("textarea#status").value();

    if(status == "") {
        return false;
    }

    var data = 'status='+status;

    $.ajax({

    type: "POST",

    url: "data.php",

    data: data,

    success: function(data) {

    $("#statustext").html(data);

    }

    });


    });

    });

    </script>
    </head>

    <body>


    <div id="global">

    <form action="" onsubmit="return false">

    <textarea id="status"></textarea>


    <button id="postbutton">POST</button>

    <a href="logout.php">LOGOUT</a>

    </form>

    <br/>
    <br/>


    <div id="allstatus">



    <!-- SKELETON -->


    <div id="status">


    <div id="statuspic">
    </div>


    <div id="statusinfo">

    <div id="statusname">JOnathan</div>
    <div id="statustext"> this is the question</div>
    <div id="statusoption"><button id="likestatus">LIKE</button></div>
    <div id="statusoption"><button id="commentstatus">COMMENT</button></div>
    <div id="statusoption"><button id="sharestatus">SHARE</button></div>
    <div id="statusoption"><button id="statustime">TIME</button></div>

    </div>

    </div>    

    <!-- SKELETON -->

    </div>

    </div>

    </body>

    </html>

    <?php

    $var = $_POST['status'];

    const DB_HOST = 'localhost';
    const DB_USER = 'root';
    const DB_PASS = '';
    const DB_NAME = 'forum';
    //connecting 

    $conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

    if($conn->connect_error) {
        die("Connection Failed: " . $conn->connect_error);
    } else {

    echo " success";

    }


    $sql = "INSERT INTO `question`(id, question) VALUES ('', '{$var}')";

    $result = $conn->query($sql);

    if($result) {

        echo "inserted successfuly";
    }
     else {

        echo "failed: " . $conn->error;
     }


    echo " the text: " .$var. " has been added to database.";


    ?>


HOW IT SHOULD WORK

I want to use JQuery/AJAX on my homepage.php to send data to data.php and that data gets returned back to homepage.php. On success to be displayed in my div #statustext.

Meaning when i write a question in textarea input field the data gets stored in database and retrieved and displayed in my div on the browser. Please help me thanks..

</div>

you should change your script like below. Ajax sends data to url in a serialize manner either you have to use form serialize which will send all the fileds info to your php url other wise if you have to send only one field value then you can do this change

<script type="text/javascript">
    //daddy code
    $ (document).ready(function() {
        //mama code
        $("button#postbutton").click(function() {
            //children code
            var status = $("textarea#status").value();
            if(status == "") {
                return false;
            }
            var data = {'status='+status};
            $.ajax({
                type: "POST",
                url: "data.php",
                data: data,
                success: function(data) {
                    $("#statustext").html(data);
                }
            });
        });
    });
</script>

POST uses name and not id so change this:

<textarea id="status"></textarea>

To this:

<textarea name="status"></textarea>

For the data make sure it's the data for your form, and add method="post" to it so it can send POST data. For example if you gave your form an id of yourForm:

HTML

<form action="" method="post" id="yourForm" onsubmit="return false">

JS

$.ajax({
    ...
    data: $("#yourForm").serialize(), 
    ...
});

First of all use .val() not .value() when you getting value of your message. Second mistake - is using two id = "sattus". Id of elements must be unique or use class = "" for ident your class of elements.

Don't give same id to more then 1 html element !

In your code :

<textarea id="status"></textarea>

and

<div id="status">

both contains same id ! Please correct it first.Also In your code as Spencer mentioned in his answer that add name attribute with value "status". No doubt as you are using jQuery selector it should pick up correct one,though you can just alert it before sending the request using AJAX.

also set data variable as var data = {status : status};