gpt4 book ai didi

javascript - onreadystatechange 里面应该有什么?

转载 作者:行者123 更新时间:2023-11-30 16:53:01 24 4
gpt4 key购买 nike

我有一个问题。我在我用来触发的外部 javascript (ajax) 中有一个删除函数,以便执行我的 PHP 文件中的删除查询。

我想知道的是 onreadystatechange 函数中应该有什么。之前有一个功能只是显示表格。 onreadystatechange函数里面是

document.getElementById("divTable").innerHTML=xmlhttp.responseText;

所以现在我很困惑,我是放同样的东西还是?删除记录后如何让查询执行并在表中显示新结果?

function.js Javascript 文件:

function deleteThis(count){

var name = document.getElementById("row"+count).innerHTML;
var page = "database.php";
var parameters = 'name='+name+'&action=delete'
var xmlhttp = new XMLHttpRequest();

if(confirm('Are you sure you want to delete this?')==true){

if(xmlhttp==null){
alert("Your browser does not support ajax!");
return false;
}
xmlhttp.onreadystatechange=function(){
//what should be in here
};
xmlhttp.open("GET", page+"?"+parameters, true);
xmlhttp.send(null);
}
}

在 database.php 文件中:

                      .
.
Other lines of code
.
.


function deleteRow($name){
$table_info = "info";

$query_string = "delete from $table_info where id = '$name'";
$result = @mysql_query($query_string);
}
?>

<?php
$name = rtrim($_REQUEST['name']);
$action = rtrim($_REQUEST['action']);

if($action=="delete"){
echo deleteRow($name);
}
else{
echo update_database();
}
?>

最佳答案

来自 MDN

Returns a EventHandler that is called whenever the readyState attribute changes. The callback is called from the user interface thread.

所以当readyState改变时,你可以在这个属性中看到请求的状态。

0 UNSENT open() has not been called yet.

1 OPENED send() has been called.

2 HEADERS_RECEIVED send() has been called, and headers and status are available.

3 LOADING Downloading; responseText holds partial data.

4 DONE The operation is complete.

关于javascript - onreadystatechange 里面应该有什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30206827/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com