簡體   English   中英

未捕獲類型:未定義不是函數JS錯誤

[英]Uncaught Type: Undefined is not a function JS error

我一直在尋找並嘗試使用許多找到的解決方案,但在我的情況下不起作用。 在我的帶有下拉更改事件的MVC 4應用程序中,我正在調用JS方法,以將選定的值傳遞給控制器​​,該控制器可以正常工作,但是在控制台中,每次更改事件中我都會不斷收到此錯誤。

以下是我的下拉列表的剃須刀來源:

    <div>
        @Html.LabelFor(model => model.CustId) 
        @Html.DropDownListFor(model => model.CustId, new SelectList(Model.ddlCust, "Value", "Text"), "All Customer", new { id = "CustID", onchange = "ShowCust()", @class = "form-control" })
        @Html.ValidationMessageFor(model => model.CustId)
   </div> 

我的JS客戶端函數如下所示:

<script>
    function ShowCust() {
            var custId = $("#CustID").val();
            var Url = "@Url.Content("~/Customer/GetCustId")";
            $.ajax({
                url: Url,
                type: 'POST',
                dataType: 'json',
                data: { CustID: custId },
                success: function (data) {
                    return data;
                }
            });
        }
</script>

在控制台中,它會在每次下拉更改時引發錯誤:

uncaught type error: undefined is not a function.

最后在源代碼中顯示為:

<script>(function() {with (this[2]) {with (this[1]) {with (this[0]) {return function(event) {ShowCust()
};}}}})</script>

另外,它還在函數ShowCust( { ShowCust)之前的括號中用下划線標記該部分。

我無法弄清楚我在這里到底在做什么錯。

有人看到我的html或javascript有任何問題嗎? 還是我編寫腳本的方式? 提前致謝。

I think you have miss out the '@' for Id & onChange

new {@id =“ CustID”,@onchange =“ ShowCust()”,@class =“ form-control”})

@id =“ CustID” @onchange =“ ShowCust()”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM