Ajax将数据发布到PHP

I have the following code:

  <?php
        $query=mysqli_query($mysqli, "SELECT assignment,a_id FROM assignments WHERE groupid='".$groupid."'");
        $assignments = array(); // create empty assignments array

        while ($row=mysqli_fetch_array($query)){
            echo'<td class="columnname" id="'.$row['a_id'].'" contenteditable="true">'.$row['assignment'].'</td>';
            $assignments[$row['a_id']] = $row['assignment']; // add assignment to array

        }
        ?>

      <script>
$('.columnname').keyup(function() {
    delay(function(){

        var text= $(this).text();
        var id= $(this).attr('id')
        $.ajax({
            type:"POST",
            url:"updateassignment.php",
            data:{text:text, id:id},
            success:function(data){
                console.log('success bro!');
            }
        });
    }, 500 );
});

var delay = (function(){
    var timer = 0;
    return function(callback, ms){
        clearTimeout (timer);
        timer = setTimeout(callback, ms);
    };
})();
</script>  

Basically what happens, is that i have a contenteditable and whenever that is keyup (which means whenever user types in info), it will post the data to the php file updateassignment.php which updates the values. However, it doesnt seem to work for me, it gives me the success result, but shows no error. Its sort of not getting the values from the fields, but as you can see, im using $(this) which refers to the columnname class (which is generated dynamically by php)

The php updateassignment file code is below:

<?php
include_once("config.php");

if (isset($_POST['id']) && isset($_POST['text'])) {

    $id=$_POST['id'];
    $text=$_POST['text'];

    $query=mysqli_query($mysqli, "UPDATE assignments SET assignment='$text' WHERE a_id='$id'")or die(mysqli_error($mysqli));


}


?>

I have a feeling that the this is not refering the correct element, therefore contenteditable's ajax is unable to grab the correct value.

I found the answer.

It was because i defined the ajax this inside the delay function, so it would not reference the columnname. The way to solve this is to define $(this) outside of the delay function.