0

http://christianselig.com/contact.html

在此联系页面上,当我单击提交时,它不会按应有的方式提交页面。AJAX 应该删除表单并输入错误或成功消息。但它不会。如果我注释掉error:部分,它会完美运行。

jQuery:

$.ajax({  
                type: "POST",  
                url: "mail.php",  
                data: dataString,  
                success: function(data) { 
                    $(".contact-form").hide();
                    $(".alt-contact").hide();

                    // Depending on what the PHP script returned, display a message of success or error
                    if (data == 1) {
                        $(".contact-form").html("<div class='success-message'><div class='success-image'></div><div class='success-title'>Success! The message has been sent!</div><div class='success-body'>I'll get back to you right away.</div></div>");
                    }
                    else {
                        $(".contact-form").html("<div class='error-message'><div class='error-image'></div><div class='error-title'>Whoops! An error occurred.</div><div class='error-body'>I'll get back to you ASAP.</div></div>");
                    }

                    $(".contact-form").fadeIn(500);
                }
                error: function(jqXHR, textStatus, errorThrown) {
                    $(".contact-form").hide();
                    $(".alt-contact").hide();

                    // Inserts divs making up the success message for the form submission
                    $(".contact-form").html("<div class='error-message'><div class='error-image'></div><div class='error-title'>Success! The message has been sent!</div><div class='error-body'>I'll get back to you right away.</div></div>");

                    $(".contact-form").fadeIn(500);
                }
            });
4

3 回答 3

3

您在指定错误时忘记了逗号:

$.ajax({  
    type: "POST",  
    url: "mail.php",  
    data: dataString,  
    success: function(data) { 
        // code
    }, <----- Right there!
    error: function(jqXHR, textStatus, errorThrown) {
        // code
    }
});
于 2012-09-26T17:58:29.707 回答
0

您在错误之前缺少逗号“,”。逗号是变量、对象等之间的分隔符。

于 2012-09-26T17:58:14.100 回答
0

分隔属性时缺少逗号

     $(".contact-form").fadeIn(500);
 } ,  <--------      Missing a comma here
 error: function(jqXHR, textStatus, errorThrown) {
于 2012-09-26T17:59:41.357 回答