如何在html按钮上触发sql查询?
答案 0 :(得分:1)
我会使用jQuery。
$("#submit").on("click", function(){
$.ajax({
type: "post",
url: "process.php",
data:"action=SomeActionHere",
success: function(data){
alert("SUCCESS");
},
error: function(e){
alert("ERROR");
}
});
};

<!--index.html -->
<button id="submit">GOGO</button>
<!--process.php-->
<?php
header("Content-type: application/json; charset=utf-8");
//connecto to server
$action = $_POST['action'];
if($action == "SomeActionHere"){
// do you sql stuff here
// when done sql
echo json_encode("SUCCESS"); // whatever data you want to send back
}
?>
&#13;