如何用 SweetAlert 替换此 Ajax 警报?
How do I replace this Ajax alert with SweetAlert?
我在这里浏览了很长时间以寻找解决方案,但从未发布过...直到现在!
我尝试了各种变体,我确信这很简单,但我被卡住了。我有以下 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 替换 function(response) 部分,但由于警报功能上方的附加代码,我感到困惑。以下是我想放入其中的 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>
我在这里浏览了很长时间以寻找解决方案,但从未发布过...直到现在!
我尝试了各种变体,我确信这很简单,但我被卡住了。我有以下 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 替换 function(response) 部分,但由于警报功能上方的附加代码,我感到困惑。以下是我想放入其中的 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>