Я пытаюсь, чтобы моя страница показывала форму отправки текстовой области HTML после того, как пользователь нажимает кнопку с помощью AJAX, но по какой-то причине в ответе AJAX отображается все, кроме текстовой области. Я немного новичок в веб-разработке, поэтому мой код - беспорядок. Я удалил некоторые вещи из кода, чтобы их было легче читать, но приведенный ниже код все еще не работает. Часть javascript:
var time_variable;
function getXMLObject() //XML OBJECT
{
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+
}
catch (e2) {
xmlHttp = false // No Browser accepts the XMLHTTP Object then false
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers
}
return xmlHttp; // Mandatory Statement returning the ajax object created
}
var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object
var poll_id;
function getVote(choice, id, poll, display) {
switch(poll)
{
case 1:
poll_id = '1';
break;
case 2:
poll_id = '2';
break;
case 3:
poll_id = '3';
break;
default:
alert("Error in poll ID..");
}
var getdate = new Date(); //Used to prevent caching during ajax call
if(xmlhttp) {
//var txtname = document.getElementById("txtname");
xmlhttp.open("POST","poll_vote.php",true); //calling testing.php using POST method
xmlhttp.onreadystatechange = handleServerResponse;
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send("choice=" + choice + "&id=" + id + "&disp=" + display); //Posting txtname to PHP File
}
}
function handleServerResponse() {
if (xmlhttp.readyState == 4) {
if(xmlhttp.status == 200) {
document.getElementById("poll"+poll_id).innerHTML=xmlhttp.responseText; //Update the HTML Form element
}
else {
alert("Error during AJAX call. Please try again");
}
}
}
Кнопки для нажатия:
<div id="poll1">
<table id="pollm"><tr><td>
<a href="#" onclick="getVote(0,<?php echo $id; ?>,1,'m')" ><img src="/Images/A_not_pressed_small.png" border="0" onmouseover="this.src='/Images/A_pressed_small.png';" onmouseout="this.src='/Images/A_not_pressed_small.png';" /></a>
</td><td>
<?php echo $current['choice1']; ?>
</td></tr>
</table>
<table id="pollm"><tr><td>
<a href="#" onclick="getVote(1,<?php echo $id; ?>,1,'m')" ><img src="/Images/B_not_pressed_small.png" border="0" onmouseover="this.src='/Images/B_pressed_small.png';" onmouseout="this.src='/Images/B_not_pressed_small.png';" /></a>
</td><td>
<?php echo $current['choice2']; ?>
</td></tr>
</table>
</div>
И poll_vote.php - это просто таблица:
<table width="200" border="0" cellpadding="0" cellspacing="0" >
<tr>
<form name="form1" method="post" action="add_comment.php">
<td><textarea name="a_answer" cols="45" rows="3" id="comment"></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Submit" class="text_submit"></td>
<td>hello world!</td>
<td></td>
</tr>
</table></td></tr>
</table>
После того, как я нажму кнопку, я смогу увидеть кнопку отправки и "Привет, мир!" Ответ AJAX, но нет текстовой области. У кого-нибудь есть предложения, пожалуйста? Спасибо