gpt4 book ai didi

mysql - 数据库更新时 Ajax 自动更新

转载 作者:行者123 更新时间:2023-11-29 03:09:08 25 4
gpt4 key购买 nike

我需要我的文本在 mySQL 数据库更新时自动更新。有人可以帮忙吗?我看了很多,没有帖子说我需要什么,我是 ajax 的新手,对此了解不多。我只知道 HTML、CSS、PHP 和 javascript。

最佳答案

首先,您可能想查看 jQuery .如果你会 javascript,这将非常简单,并且会让你的开发变得容易很多。

然后你需要检查 ajax call是用 jQuery 实现的。同样,非常简单,这是一个示例。

test.php

$var1 = $_POST['key'];
$var2 = $_POST['key1'];

//Some code here

echo 'Test finished'; // This is returned to the ajax call

JavaScript

$.ajax({
url: '/test.php',
type: 'POST', /*Method, POST or GET depending on your needs*/
async: true, /*This makes the ajax call asyncronously or not*/
data: {'key':value,'key2':value2},/*data to send*/
success: function(result){ /*Return from PHP side*/

/* result contains the data replied from the PHP script. */
alert(result);

}
});

如果您想替换 H​​TML 的某些部分,您可能需要检查函数,例如 append , after , before , prependhtml ,ETC。还了解一些关于 JSON 的信息,这是一种数据格式。真的很简单,但又很壮观

希望对您有所帮助!这看起来像是家庭作业,但您很快就会做好,您会明白的。

关于mysql - 数据库更新时 Ajax 自动更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11007467/

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