jquery - Can't update php file via ajax $.post -


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 manually change $text var , save file, update in browser accordingly, want change putting text textarea , pressing button.

i wrote following function nothing returned.

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

how can update '$text' variable page using textarea , button?

you missing closing ) , there no echo function.

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

Comments