我必须从数据库中获取数据,但我的脑袋坏了,因为我没有发现任何错误,但我不知道为什么它不起作用!
JavaScript
var editdata = document.getElementById('editdata');
editdata.onclick = function() {
$.ajax({
url: "sendata.php",
data :{ length : length, age : age, },
type : 'POST',
success: function(output_data){
$('#mydata').html(output_data);
}
});
}
PHP
if (isset($_POST['editdata'])) {
$sql4 = $db->setQuery(
"SELECT * FROM people WHERE userid = "
. $userid2 . " AND inf_id = " . $_SESSION['name'] . " "
);
$result4 = $sql4->loadAssocList() ;
$output_data = "";
$output_data .= "<table width='600' border='1' >";
foreach ($result4 as $row4) {
$output_data .= "<tr><td>".$row4['age'];
$output_data .= "</td><td>".$row4['length'] ;
$output_data .= "</td><td><input id ='".$row4['id']
. "' type='button' value='Delete'/>";
$output_data .= "</td></tr>" ;
}
$output_data .= "</table>" ;
echo $output_data ;
}
echo "failure";
但如果我这样做,我只会收到一条failure
消息:
success: function(msg){
alert(msg);
$('#mydata').html(output_data);
}
我究竟做错了什么?