我在将 GET 变量传递到另一个 PHP 页面时遇到了问题。我有一个简单的目录。我想使用 ajax 删除行。Ajax 在带有表单的简单示例上完美运行。
这是一个标记:
while($row=mysql_fetch_array($query))
{
/*here are rows(content) */
<form action='#' method='get' onsubmit='deleteContent(); return false'>
<td><input type='hidden' name='delete' value='$row[id_content]' id='delete' />
<input type='submit' class='del' name='delete' title='Delete' value='Delete' /></td>
</tr></form>";
}
当我按下提交时,它总是返回 1。这是 DeleteContent
function deleteContent()//za brisanje dela
{
try
{
xhr = new XMLHttpRequest();
}
catch (e)
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xhr == null)
{
alert("Vaš brskalnik ne podpira AJAX-a!");
return;
}
var url = "delete.php?delete=" + document.getElementById('delete').value;
xhr.onreadystatechange = handler2;
xhr.open("GET", url, true);
xhr.send(null);
}
function handler2()
{
if (xhr.readyState == 4)
{
if (xhr.status == 200)
document.getElementById("delete").innerHTML = xhr.responseText;
else
alert("error!");
}
}
这是delete.php
<?php
echo "<span>Content delete</span><br/>";
if($_GET['delete'])
{echo $_GET['delete'];}
?>
有谁知道问题出在哪里?