注:Ajax中要加xmlhttp.setRequestHeader(“Content-type”,“application/x-www-form-urlencoded”);来来添加 HTTP 头,不然php文件无法接收到传递的值
Ajax代码:
function collectButton(recommend_id){
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", 'php/accept.php', true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("Rid="+recommend_id);
}
accept.php文件中代码:
<?php
$id = $_POST['Rid'];
echo $id;
?>
最后查看输出验证: