Uncaught TypeError: $(...).ajaxForm is not a function

Uncaught TypeError: $(...).ajaxForm is not a function

我正在尝试使用 ajaxForm 提交表单并重定向到视图。但是,我遇到了未捕获的类型错误 (...)。ajaxForm 不是函数。

我的代码:

$(document).ready(function () {
    loadMainInputs();
    loadSubCategory(<?php echo $model->category_id; ?>);
    $("#Posts-form").ajaxForm({
        beforeSend: function () {
            return $("#Posts-form").validate({
                rules: {
                    name: {
                        required: true,
                    }
                },
                messages: {
                    name: {
                        max: "Customize Your Error"
                    }
                }
            }).form();
        },
        beforeSubmit: function () {
            $("#btn-save").html("Loading....");
            $("#btn-delete").attr("disabled", true);
            $("#btn-submit").attr("disabled", true);
        },
        success: function (data) {
            var result = JSON.parse(data);
            if (result.id != 0) {
                window.location.href = "<?php echo Yii::app()->createUrl("posts"); ?>/";
            }
            showResponse(data);
        }
    });

});

ajaxForm 函数似乎不是 jQuery 的原生函数,而是来自 jQuery 插件 jQuery Form Plugin。在您的代码中包含此插件应该可以解决您的问题。