使用ajax函数后清除文本区域


Clearing the textarea after using ajax function

我有一个可用的ajax函数,用户在文本区输入一些内容,按回车键,用户输入的任何内容都将输出到屏幕上。现在我正试图找到一种方法来清除用户按下回车后的文本区域。我怎么做呢?

test .php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type = "text/javascript"> 
function ajaxPass(gotoUrl,getValueFrom,output) {
      var input = document.getElementById(getValueFrom).value; // or $('#t').val();
      $.ajax({
           type: "POST",
           url: gotoUrl,
           data: { input : input },
           error: function(xhr,status,error){alert(error);},
           success:function(data) {
           document.getElementById( output ).innerHTML = data;
           }
      });
}
</script>
<textarea id = 'textarea' rows = "25" cols = "50" onKeyDown="if(event.keyCode==13) ajaxPass('robotChat2.php','textarea','output')"> </textarea>
<div id = 'output'> </div>
test2.php
<?php
$input = $_POST['input'];
echo $input;
?>

在函数末尾添加$("#textarea").val('');

    function ajaxPass(gotoUrl,getValueFrom,output) {
          var input = document.getElementById(getValueFrom).value; // or $('#t').val();
          $.ajax({
               type: "POST",
               url: gotoUrl,
               data: { input : input },
               error: function(xhr,status,error){alert(error);},
               success:function(data) {
               document.getElementById( output ).innerHTML = data;
               }
          });
            $("#"+getValueFrom).val('');
    }