php ajax method to delete data: first receive GET parameters in the PHP file and delete the data according to the parameters; then use the function "json_encode()" to return the data; then use AJAX to request the file on the front end .
First receive the GET parameters in the PHP file and delete the data according to the parameters;
$id = $_GET['id']; /*删除数据逻辑*/
Then use the function "json_encode()" to convert the data Return;
header('Content-Type:application/json'); json_decode([ 'code' => 1, 'msg' => 'Delete success' ])
Then use AJAX to request the file on the front end;
if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码 xmlhttp=new XMLHttpRequest(); } else { // IE6, IE5 浏览器执行代码 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { alert(xmlhttp.responseText); } } xmlhttp.open("GET","del_data.php?id="+id,true); xmlhttp.send();
For more related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to delete data in php ajax. For more information, please follow other related articles on the PHP Chinese website!