ユーザーのブラウザでjavascriptが有効になっている場合はajaxを使用して入力したいテキストエリアがありますが、jsが無効になっている場合はphpを使用します。問題は、ajax と php の両方が実行され、入力されたすべての入力の double が作成されることです。noscript タグを試しましたが、何も出力されません。助けていただければ幸いです。
これが私のhtmlです:
<form action="savemessage.php" method="post" id="mainChat" name="mainChat"
onsubmit="return loadChat();">
<textarea class="historyClass" id="historyFieldjs" name="historyFieldjs" rows="40" cols="80">
<noscript>
<textarea class="historyClass" id="historyField" name="historyField" rows="40" cols="80">
<?php
echo "stuff";
?>
</textarea></noscript>
そしてJavaScript:
function loadChat()
{
var xmlhttp = new XMLHttpRequest;
xmlhttp.open("GET", "getmessages.php", true);
xmlhttp.send();
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
var results = JSON.parse(xmlhttp.responseText);
var i;
for(i=0; i<results.length; i++)
{
document.getElementById("historyFieldjs").value=
document.getElementById("historyFieldjs").value+result[i]+"\n";
}
}
}
return false;
}