通过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====
                     }
                });  
           }  
      });

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...