问题描述
我真的是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====
}
});
}
});