如何解决通过if语句通过PHP调用SweetAlert
我真的是Java的新手,所以我很难弄清楚这一点。我正在尝试使用SweetAlert 2在PHP if语句上弹出错误消息。
JavaScript:
Swal({
type: 'error',title: 'Oops...',text: 'Something went wrong!',footer: '<a href>Why do I have this issue?</a>'
})
PHP if语句:
if(mysqli_query($dbcon,$sqlinsert)) {
* SUCCESS CODE GOES HERE *
}
else {
* JAVASCRIPT CODE GOES HERE *
}
有什么想法吗? (对不起,我对JS真的很陌生)
解决方法
您也可以使用Jquery ajax方法。使用ajax方法将数据插入表中,并对成功插入jquery函数进行进一步的操作。
$('#testmForm').on("submit",function(event){
event.preventDefault();
if($('#name').val() == "")
{
swal("Somthing Wrong!","Name is required","error");
}
//Further conditions for your form inputs
else
{
$.ajax({
url:"/functions.php",method:"POST",data:$('#testmForm').serialize(),beforeSend:function(){
$('#insertTestm').val("Wait a moment...!"); //this is the submit button,will be renamed to wait a moment before performing the action.
},success:function(data){
//Here you can show your popup that data has been inserted.
$('#testmForm')[0].reset();
$('#testmData').html(data);
swal("Done!","Client's testimonial has been modified","success");
},error:function(data){
swal("Somthing Wrong!","Query error","error"); //===Show Error Message====
}
});
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。