简体   繁体   English

Uncaught TypeError:未定义不是自定义jQuery插件的函数

[英]Uncaught TypeError: undefined is not a function with custom jQuery Plugin

I have made a wrapper plugin for the jquery autocomplete plugin as we use it everywhere on our projects and need to globally change it at times, however whenever i reference the plugin i get the error: Uncaught TypeError: undefined is not a function my pluggin looks like so: 我为jquery自动完成插件制作了包装器插件,因为我们在项目中到处都使用它,有时需要对其进行全局更改,但是,每当我引用该插件时,都会收到错误消息: Uncaught TypeError: undefined is not a function我的插件看上去Uncaught TypeError: undefined is not a function像这样:

(function ($) {
$.fn.CustomAutocomplete = function (options) {
    //Settings
    alert("test");
    var settings = $.extend({
        //Defaults
        ContollerMethodLink: "",
        ReturnElement: ""
    }, options);

    $(this).autocomplete({
        source: function (request, response) {
            var employees = new Array();
            $.ajax({
                async: false,
                cache: false,
                type: "POST",
                url: ContollerMethodLink,
                data: { "query": request.term },
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        employees[i] = { label: data[i].Key, Id: data[i].Value };
                    }
                }
            });
            response(employees);
        },
        select: function (event, ui) {
            //fill selected customer details on form
            var id = ui.item.Id;
            $('#' + settings.ReturnElement).val(id);
        }
    });
}
})(jQuery);

I then call it like so: 然后我这样称呼它:

    $(document).ready(function() {
        $('#AddReportingEmpText').CustomAutocomplete({
            ReturnElement: "AddReportingEmpId",
            ContollerMethodLink: "@(Url.Action("Method", "Controllers"))",
        });
    });

However when i try to use this i get the said error in a random empty space right above $(document).ready(function() { if i hard code out the ajax request in the spot where i am currently calling my plugin, everything works fine. Any ideas? 但是,当我尝试使用此命令时,我会在$(document).ready(function() {上方的随机空白区域中得到上述错误,如果我在当前正在调用插件的地方硬编码了ajax请求,则一切工作正常,有什么想法吗?

Edit: worth noting this is my JS File call: 编辑:值得注意的是这是我的JS文件调用:

<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js" type="text/javascript"></script>

I then call my plugin file and the debugger shows me it is being properly included 然后,我调用我的插件文件,调试器显示该文件已正确包含

This appears to be well known problem with recent versions of Chrome. 对于最新版本的Chrome,这似乎是众所周知的问题。 Using FF browser will provide with more detailed information about the error 使用FF浏览器将提供有关错误的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM