简体   繁体   中英

how to show success message after sending email using sweet js

I'm trying to send email without reloading page . But after sending it should show success message using sweet js . Unfortunately it doesn't work .

 $(document).ready(function(){ $('#contact-form').on('submit',function(e) { $.ajax({ url:'mailer.php', //===PHP file name==== data:$(this).serialize(), type:'POST', success:function(data) { console.log(data); //Success Message swal("¡Success!", "Message sent!", "success"); }, error:function(data) { //Error Message swal("Oops...", "Something went wrong :(", "error"); } }); e.preventDefault(); }); });

you can return something so you can know if the mail was sent or not,

by comparing the data

so you can do the following in the success part of the ajax:

success:function(data) {
if(data == 'something that you will know if it sent'){
    swal("¡Success!", "Message sent!", "success");
      },

}

also make sure that you put the scr of the sweet alert in the head.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM