无法通过ajax $ .post更新php文件

I have this:

<div class="text_window"></div>
<textarea></textarea>
<button>Send</button>

$(function() {
    getStatus();
});

function getStatus() {

    $.post('update.php', function(data) {
        $('div.text_window').html(data);
    });
    setTimeout("getStatus()",1000);
}

update.php

$text = $_POST['text'];
if (!$text) $text = 'string';
echo $text;

Now, if I manually change the $text var and save the file, it will update in the browser accordingly, but I want to change it by putting text into the textarea and pressing the button.

I wrote the following function but nothing is returned.

$('button').click(function() {
    update();
});

function update() {
    var text = $('textarea').val();
    $.post('update.php',{text:text}, function(data) {
        alert ('ok');
    });
}

How can I update the '$text' variable from this page using the textarea and the button?

You are missing the closing ) and there is no echo function.

function update() {
    var text = $('textarea').val();

    $.post('update.php',{text:text}, function(data) {
       // echo 'ok';
       alert('ok');
       console.log('ok')
    }); // here
}

Try:

$.post('update.php',{text:text}, function(data) {
    echo 'ok';
});