如何解决如何用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!"; }
谢谢:)
解决方法
恭喜您在堆栈溢出方面的第一个问题!
我认为您可以这样写:
<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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。