未捕获RangeError:超出最大调用堆栈大小。 JavaScript的

时间:2016-09-29 21:28:13

标签: javascript jquery twitter-bootstrap

我需要一些帮助来解决这个错误的来源。根据控制台,它在这个函数中被抛入jquery.min.js:

function buildParams( prefix, obj, traditional, add ) {
var name;

if ( jQuery.isArray( obj ) ) {

    // Serialize array item.
    jQuery.each( obj, function( i, v ) {
        if ( traditional || rbracket.test( prefix ) ) {

            // Treat each array item as a scalar.
            add( prefix, v );

        } else {

            // Item is non-scalar (array or object), encode its numeric index.
            buildParams(
                prefix + "[" + ( typeof v === "object" && v != null ? i : "" ) + "]",
                v,
                traditional,
                add
            );
        }
    } );

} else if ( !traditional && jQuery.type( obj ) === "object" ) {

    // Serialize object item.
    for ( name in obj ) {
        buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
    }

} else {

    // Serialize scalar item.
    add( prefix, obj );
}
}

我相信它专门在这个循环中投入:

// Serialize object item.
for ( name in obj ) {
    buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
}

我使用的是一个稍微修改过的模板,我从bootstrap网站获得,但我显然没有修改此文件,我认为它应该开箱即用。提交以下表单时会触发错误:

<form name="sentMessage" id="contactForm" novalidate>
....
</form>

由js控制。

$("#contactForm input,#contactForm textarea").jqBootstrapValidation({
    preventSubmit: true,
    submitError: function($form, event, errors) {
        // additional error messages or events
    },
    submitSuccess: function($form, event) {
        event.preventDefault(); // prevent default submit behaviour
        // get values from FORM
        var firstName = $("#fname").val();
        var lastName = $("#lname").val();
        var email = $("#email").val();
        var cphone = $("#cphone").val();
        var comment = $("#comment").val();
        var address = $("#address").val();
        var city = $("#city").val();
        var zip = $("#zip").val();

        $.ajax({
            url: "iveTriedDifferentActionsHere",
            type: "POST",
            data: {
                fname: fname,
                lname: lname,
                cphone: cphone,
                email: email,
                comment: comment,
                address: address,
                city: city,
                zip: zip
            },
            cache: false,
            success: function() {
                // Success message
                $('#success').html("<div class='alert alert-success'>");
                $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                $('#success > .alert-success')
                    .append("<strong>Your message has been sent. </strong>");
                $('#success > .alert-success')
                    .append('</div>');

                //clear all fields
                $('#contactForm').trigger("reset");
            },
            error: function() {
                // Fail message
                $('#success').html("<div class='alert alert-danger'>");
                $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                    .append("</button>");
                $('#success > .alert-danger').append("<strong>Sorry " + firstName + ", it seems that my mail server is not responding. Please try again later!");
                $('#success > .alert-danger').append('</div>');
                //clear all fields
                $('#contactForm').trigger("reset");
            },
        });
    },
    filter: function() {
        return $(this).is(":visible");
    },
});

我知道这是很多代码,但它是必需品。我似乎无法弄清楚造成它的原因。我尝试了不同的动作,不同的输入,但我的想法已经不多了。提前感谢您的帮助。

0 个答案:

没有答案