mysql - 如何用 SweetAlert 替换此 Ajax 警报?
问题描述
我是在这里寻找解决方案的长期浏览器,但从未发布过……直到现在!
我尝试了各种变化,我确信这很简单,但我被卡住了。我有以下 Ajax 脚本来更新我的数据库中的记录。
<button class="btn btn-dark" type="submit" id="update"><i class="fas fa-edit"></i> UPDATE</button>
<script>
$(document).ready(function(){
$("#update").click(function(){
var fname=$("#fname").val();
var thestore=$("#thestore").val();
$.ajax({
url:'update.php',
method:'POST',
data:{
fname:fname,
thestore:thestore
},
success:function(response){
alert(response);
}
});
});
});
</script>
我正在尝试用 SweetAlert替换功能(响应)部分,但由于警报功能上方的附加代码,我感到困惑。以下是我想放在那里的 SweetAlert 代码:
swal("Good job!", "You have updated the record!", "success")
任何人都可以帮助我如何最好地将其合并到我现有的 Ajax 代码中吗?
这是 update.php 进程结束并显示警报的地方:
$conn = new mysqli('localhost', 'root', '', 'my_db');
$name=$_POST["fname"];
$thestore=$_POST["thestore"];
$sql="UPDATE feedback set firstName='$name', store='$thestore' where id=1";
if($conn->query($sql)===TRUE){
echo "You have updated the record!"; }
谢谢 :)
解决方案
恭喜您在 Stack Overflow 上提出第一个问题!
我想你可以这样写:
<button class="btn btn-dark" type="submit" id="update"><i class="fas fa-edit"></i> UPDATE</button>
<script>
$(document).ready(function(){
$("#update").click(function(){
var fname=$("#fname").val();
var thestore=$("#thestore").val();
$.ajax({
url:'update.php',
method:'POST',
data:{
fname:fname,
thestore:thestore
},
success:function(response){
// alert(response);
swal("Good job!", response, "success");
}
});
});
});
</script>
推荐阅读
- laravel - 如何在多态(laravel 6)中保存id和模型?
- flutter - Flutter 上用于位置设置的本机对话框
- javascript - 计数器点击保存 Cookie
- function - 按多列从 GBQ 表中删除重复项的最有效方法
- android - 如何在 Kotlin/Arrow.kt 中为 producer Channel 实现“铁路模式”
- python - VSCode Python 写入调试控制台
- .net-core - 如何在没有 App.runtimeconfig.json 的情况下构建 App?
- azure - 是否可以从另一个网络向服务器发出请求
- json - 在转换为 CSV 之前,使用 JQ 将 JSON 嵌套对象输出到数组中
- kubernetes - Kubeam 失败 | 服务已关闭