【发布时间】:2009-08-18 22:01:29
【问题描述】:
我有一组在表中动态生成的链接。每一行的标签上都有一个唯一的“id”属性。目标是让 XMLHTTPRequest 告诉页面“deletepost.php”要从外部数据库中删除哪条记录。
它将隐藏的输入值更改为行的值(一个数字),然后提交该表单
<script type="text/javascript">
var http = false ;
// instance the request object!!!!
if(navigator.appName == "Microsoft Internet Explorer") {
http = new ActiveXObject("Microsoft.XMLHTTP");
} else {
http = new XMLHttpRequest();
}
/////////////////////////////////////////////////
function rdel(num) {
document.getElementById("pid_to_del").value = num;
//this element is a hidden <input> tag. this line changes the value.
http.open("POST", "deletepost.php", true); //this _SHOULD_ post the form
http.onreadystatechange = function() {
if(http.readyState == 4) {
$("tr#r" + num).fadeOut("slow"); // jquery fadeout animation
alert(http.responseText); // this alerts whatever deletepost.php says
}
}
http.send(null);
}
</script>
此函数 rdel() 由其中一个链接调用,如下所示:
<a href="javascript:rdel('7');"> delete </a>
这就是 deletepost.php 的样子:
<?php
print_r($_POST);
?>
发出请求警报的页面:
数组 ( )
一个空数组。 :(为什么?!
【问题讨论】:
标签: php javascript jquery ajax post