嘿,我在传递我的 php 代码的 Javascript-PHP 变量中有问题:
<li id="' . $todo1 . '" class="items">' . $todo1 . '<button onclick="ajaxdelete(' . $todo1 . ')">Delete</button></li>
继承人的javascript函数
function ajaxdelete(x){
var hr = new XMLHttpRequest();
var url = "ajaxtododelete.php";
var vars = "todo="+x;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
hr.send(vars); // Actually execute the request
}
还有我的 ajax 文件:
<?php
session_start();
include_once "connect_to_mysql.php";
$todo = $_POST['todo'];
print "$todo";
$sql = mysql_query("DELETE FROM todo WHERE todo='$todo'");
?>
因此,它不是输出“$todo1”的值(这是我想要的),而是输出: object HTMLLIElement.Any way around this?