简体   繁体   English

将表单发送到电子邮件(AJAX,Bootstrap,Jquery)

[英]Sending a form to email (AJAX, Bootstrap, Jquery)

I'm trying to send a form to email with what i have below. 我正在尝试将下面的内容发送到电子邮件中。 It's a modded version of the Bootstrap Validator by 1000hz. 它是1000hz引导程序验证器的改进版本。

$('#form').validator().on('submit', function (e) {
  if (e.isDefaultPrevented()) {
    alert("not working");
  } else {
    alert("Hello! I am working");
  }
})

to

$('#form').validator().on('submit', function (e) {
  if (e.isDefaultPrevented()) {
    alert("not working");
  } else {
       var Name = $("input#Name").val();
       var Service = $("input#Service").val();
       var Email = $("input#Email").val();
       var Message = $("textarea#Message").val();
       //ajax magic
   $.ajax({
              url: "squote-send.php", // email sender file
              type: "POST",
              data: {Name: Name, Service: Service, Email: Email, Message: Message},
              cache: false,
              success: function() {
                                  $('#success').html("<div class='alert alert-success alert-dismissible' role='alert'>");
                 $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert'><span aria-hidden='true'>&times;</span><span class='sr-only'>Close</span>")
                .append( "</button>");
                $('#success > .alert-success')
                .append("<strong>Your message has been sent. </strong>");
      $('#success > .alert-success')
      .append('</div>');

  }
})

It is not sending? 不发送吗?

Simply by adding the 只需添加

`event.preventDefault();`

fixed my problem. 解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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