jQuery / Ajax联系表单的控制台错误

时间:2014-01-12 14:22:18

标签: javascript php jquery ajax

尝试使用Ajax设置联系表单时出现以下错误:

send
v.extend.ajax
(anonymous function)
v.event.dispatch
o.handle.u

Link to live site

的jQuery

( function($) {

    $(document).ready(function() {

        $("#get-contact-form").submit(function() {

            var str = $(this).serialize();

            $.ajax({
                type: "POST",
                url: "http://ppplasmaltd.co.uk/templates/plasma/html/com_contact/contact/contact-form-process.php",
                data: str,
                success: function(msg) {

                    $(document).ajaxComplete(function(event, request, settings) {

                    if (msg === 'OK') {
                        result = '<div class="thanks" id="thanks">Thank you, we will reply <span>shortly.</span></div>';

                    else
                    {
                        result = msg;
                    }

                    });
                }
            });
        return false;
        });
    });
} ) ( jQuery );

如何解决这个问题的任何帮助都会很棒......

我对jQuery / Ajax很新。

1 个答案:

答案 0 :(得分:0)

无需在ajaxComplete success的{​​{1}}回调中放置$.ajax()。您还缺少一个右括号(})。

尝试以下方法:

(function($) {
    $(document).ready(function() {
        $("#get-contact-form").submit(function() {
            var str = $(this).serialize();

            $.ajax({
                type: "POST",
                url: "http://ppplasmaltd.co.uk/templates/plasma/html/com_contact/contact/contact-form-process.php",
                data: str,
                success: function(msg) {

                    if (msg === 'OK')
                    {
                        result = '<div class="thanks" id="thanks">Thank you, we will reply <span>shortly.</span></div>';
                    }
                    else
                    {
                        result = msg;
                    }
                }
            });
        return false;
        });
    });
}) (jQuery);