Home > Backend Development > PHP Problem > How to delete data in php ajax

How to delete data in php ajax

藏色散人
Release: 2023-03-02 08:46:01
Original
2307 people have browsed it

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 .

How to delete data in php ajax

First receive the GET parameters in the PHP file and delete the data according to the parameters;

$id = $_GET['id'];
/*删除数据逻辑*/
Copy after login

Then use the function "json_encode()" to convert the data Return;

header('Content-Type:application/json');
json_decode([
'code' => 1,
'msg' => 'Delete success'
])
Copy after login

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();
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template