我有一個頁面顯示一個表格,並在每個表格行中嵌入一個表單,該表單將從下拉菜單中提交一些數據。我正在使用AJAX製作頁面。以下是我在php頁面中迴應的內容。由ajax生成的PHP表單不起作用
echo "<table id=\"comp\">";
echo "<tr>
<th> CID </th>
<th> USERNAME </th>
<th> NAME </th>
<th> DESCRIPTION </th>
<th> ADDRESS </th>
<th> PHONE </th>
<th> DATE </th>
<th>Choose JE</th>
<th></th>
</tr>";
for($i=0;$i<$count;$i++)
{
$c = mysql_result($result, $i, 'cid');
echo "<form name=\"$i\" action=\"je_select.php\" method=\"post\">
<tr id=\"$i\">";
echo "<td>".$c."</td>";
echo "<td>".mysql_result($result, $i, 'uname')."</td>";
echo "<td>".mysql_result($result, $i, 'name')."</td>";
echo "<td>".mysql_result($result, $i, 'desc')."</td>";
echo "<td>".mysql_result($result, $i, 'address')."</td>";
echo "<td>".mysql_result($result, $i, 'phone')."</td>";
echo "<td>".mysql_result($result, $i, 'date')."</td>";
echo "<td>$dropdown</td>";
echo "<td><input type=\"hidden\" name=\"cid\" value=\"$c\"/><input type=\"submit\" value=\"Forward\"/></td>";
echo "</tr></form>";
}
echo "</table>";
現在的問題是,表單顯示正常,但點擊提交按鈕表單不會提交。它什麼都不做。雖然我的另一個項目上的類似代碼工作得很好。
請幫我解決這個問題。我被困住了,我需要快速完成這個項目。
EDIT
我試圖打開的源代碼本。而我所看到的是表單標籤在它被打開的同一個地方關閉:
<form name=\"$i\" action=\"je_select.php\" method=\"post\"></form>
爲什麼會發生這種情況??。我也看到了帖子:Form Issue (closing itself early in table)
我打開了「tr」標籤之前的表單標籤,但它仍然不起作用。我注意到
更多
一件事是,在AJAX頁面的源代碼表中也有無法解釋的原因TBODY標籤。雖然tbody標籤也出現在我的一個較老的項目中,但類似的東西在那裏工作。請幫幫我。
AJAX功能
的鏈接被點擊至:
<div id="choices">
<ul id="clist">
<a href="#" onclick="ajax(1);"><li>Pending Complaints</li></a>
<a href="#" onclick="ajax(2);" ><li>Handled Complaints</li></a>
<a href="logout.php" ><li>Logout</li></a>
<div class="clear"></div>
</ul>
</div>
功能的ajax:
function ajax(val) {
var xmlhttp;
if (active != val) {
active = val;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if (xhr) {
xhr.abort();
}
xhr = xmlhttp;
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("content").innerHTML=xmlhttp.responseText;
document.getElementById("banner").innerHTML=arr[val - 1];
}
}
xmlhttp.open("GET","dispcae.php?&s="+val , true);
xmlhttp.send();
}
}
您是否嘗試剝離的形式訪問Ajax和它自己的測試呢?一些基本的解決問題的嘗試在這裏不會錯過... – naththedeveloper
@FDL:雅試過,它在那裏工作。事實上,我實際上在做的是當用戶打開頁面時,他默認看到這個表格。但是,如果他選擇其他菜單項,則使用ajax打開這些菜單項,包括此表。 – tapananand
因爲它包含在循環中,所以你在呼應多個表單 – Shadow