after submitting a form to email i get 2 email instead 1

This question already has an answer here:

  • event.preventDefault() vs. return false 11 answers

  • I guess that #subBusinessOne is a form submit button. You're sending an AJAX request and then submitting the form again as a normal HTTP request.

    Instead of detecting button click event, you should check if the form has been submitted, then prevent default action and send the AJAX request. Your JS code would then look like this:

    app.controller('threeCtrl',function($scope){
        $("#businessFormOne").submit(function(e) {
    
        e.preventDefault(); // this is to avoid the actual submit
    
        var url = "businessFormOne.php"; 
        $.ajax({
                   type: "POST",
                   url: url,
                   data: $("form#businessFormOne").serialize(), 
                   success: function(data)
                   {
                       var name = $("input[name=name]").val("");
                       var rel= $("input[name=phone]").val("");
                   }
                 });
            });
        });
    

    app.controller('threeCtrl',function($scope){
        $("#subBusinessOne").submit(function(e) {
        e.preventDefault();
        var url = "businessFormOne.php"; 
        $.ajax({
                   type: "POST",
                   url: url,
                   data: $("form#businessFormOne").serialize(), 
                   success: function(data)
                   {
                       var name = $("input[name=name]").val("");
                       var rel= $("input[name=phone]").val("");
                   }
                 });
            });
        });
    

    使用.preventDefault()

     app.controller('threeCtrl',function($scope){
            $("#subBusinessOne").click(function(e) {
            e.preventDefault();
            var url = "businessFormOne.php"; 
            $.ajax({
                       type: "POST",
                       url: url,
                       data: $("form#businessFormOne").serialize(), 
                       success: function(data)
                       {
                           var name = $("input[name=name]").val("");
                           var rel= $("input[name=phone]").val("");
                       }
                     });
            return false; // avoid to execute the actual submit of the form.
                });
            });
    
    链接地址: http://www.djcxy.com/p/19520.html

    上一篇: 如何防止“输入提交”的违规行为?

    下一篇: 在向电子邮件提交表单之后,我会收到2封电子邮件1