联系表单的AJAX POST返回500错误

时间:2015-09-01 19:05:45

标签: javascript jquery ajax forms

我在node.js工作并使用Nodemailer。我有一个使用AJAX的联系表单,在提交时会产生500错误。以下是我作为回复获得的内容,以及下面表单的代码。我也在表单上使用csrf_token。我尝试删除它,但它没有帮助。我试过使用GET,但我仍然得到同样的错误。我真的很困惑。

$('#contactForm').find('input,textarea').jqBootstrapValidation({
    preventSubmit: true,
    submitError: function(form, event, errors) {
        // additional error messages or events
    },
    submitSuccess: function(form, event) {
        toggleSubmit(form);
        event.preventDefault(); // prevent default submit behaviour

        // get values from FORM
        var name = $("input#name").val(); 
        var email = $("input#email").val();
        var phone = $("input#phone").val();
        var message = $("textarea#message").val();
        var firstName = name; // For Success/Failure Message
        // Check for white space in name for Success/Fail message
        if (firstName.indexOf(' ') >= 0) {
            firstName = name.split(' ').slice(0, -1).join(' ');
        }
        $.ajax({
            url: "/contactus",
            type: "POST",
            data: {
                name: name,
                phone: phone,
                email: email,
                message: message
            },
            cache: false,
            success: function() {
                showStatus(form, 'success', 'Your message has been sent.');
                //$('#contactForm').trigger("reset");
            },
            error: function() {
                showStatus(form, 'danger', 'Sorry ' + firstName + ', it seems that my mail server is not responding. Please try again later!');
                $('#contactForm').trigger("reset");
                toggleSubmit(form);
            },
            complete: function(data) {
            },
        });
    },
    filter: function() {
        return $(this).is(":visible");
    },
});

处理表单的代码是:

MulticastSender(const std::string& multicastaddress,
                const unsigned short port) : Port(port),
                                             Endpoint(boost::asio::ip::address::from_string(multicastaddress), port),
                                             Socket(IOService, Endpoint.protocol()),
                                             Work(IOService) {
    auto self = this;
    WorkThread = std::thread([self]()
                             {
                                 self->IOService.run();
                             });

    std::string data = "Test message";
    Socket.async_send_to(boost::asio::buffer(data), Endpoint, boost::bind(&MulticastSender::SendHandler, this, boost::asio::placeholders::error));
}

1 个答案:

答案 0 :(得分:0)

https://en.wikipedia.org/wiki/List_of_HTTP_status_codes 500是内部服务器错误,如果您使用Node,则可能是一些未捕获的异常。您必须查看服务器代码才能找到问题。