1
사용자 브라우저에서 javascript가 활성화되어 있으면 ja로 채우기를 원하지만 js가 비활성화 된 경우에는 php를 사용합니다. 문제는 ajax와 php가 모두 실행되어 입력 된 모든 입력의 두 배가되는 것입니다. noscript 태그를 시도했지만 아무 것도 출력하지 않습니다. 어떤 도움을 주시면 감사하겠습니다.자바 스크립트가 활성화되어 있으면 PHP가 실행되지 않도록합니다.
<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>
그리고 자바 스크립트 :
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;
}
PHP가 필드를 채우고 JavaScript가 활성화 된 경우 필드를 지우고 데이터를로드하십시오. –
@RocketHazmat는 답변이 아니라 답변으로 답변을 게시합니다. – TravisO
고마워, 저렇게 훌륭합니다. – mjr