在html按钮上触发sql请求

时间:2017-04-21 08:41:17

标签: html sql

如何在html按钮上触发sql查询?

1 个答案:

答案 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;
&#13;
&#13;