我想在我的HTML页面上有一个简单的按钮,如果右键单击它,点击激活每次我的PHP脚本。 我试着用这个代码,而无需为那一刻的任何积极的结果:PHP验证按钮
//My html code
<!DOCTYPE html>
<head>
<title><?php echo $pageTitle; ?></title>
<meta charset="UTF-16" />
<link rel="stylesheet" type="text/css" media="all" href="css.css">
<style></style>
</head>
<body>
<main>
<button onclick="doTheFunction();">Run the script</button>
<script>
function doTheFunction(){
xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","script.php",true);
xmlhttp.send();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML = this.responseText;
}
};
}
}
</script>
</main>
<footer>
<?php echo $footer; ?>
</footer>
</body>
我的PHP代码的一部分:
echo "$result";
这是有点不清楚你期望什么?你也没有对你的ajax调用做任何事情。 – kabanus