簡體   English   中英

我有錯誤未捕獲的TypeError:無法讀取未定義的屬性'toLowerCase'

[英]I have the error Uncaught TypeError: Cannot read property 'toLowerCase' of undefined

錯誤

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined (jquery.min.js:2)
at w.fn.init.val (jquery.min.js:2)
at Object.error (Default.aspx:380)
at u (jquery.min.js:2)
at Object.fireWith [as rejectWith] (jquery.min.js:2)
at k (jquery.min.js:2)
at XMLHttpRequest.<anonymous> (jquery.min.js:2)

您好,這是我的錯誤。 我在網上搜索,但其他已解決的問題與我的代碼不同。

我的代碼:

$(".selectProjectElement").change(function () {
            $.ajax({
                method: "POST",
                url: "Default.aspx/affectProject",
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                data: "{ id:" + $(this).parent().parent().attr("data-id") + ", elementCode:'" + $(this).val() + "', userID:'" + $("#hidden_userID").val() + "' }",
                success: function () {
                    alert("reussi");
                },
                error: function (xhr) {
                    alert("F" + $(this).val() + "F");
                    //alert("Une erreur est survenue.");
                    window.location.pathname = window.location.pathname;
                }
            });
        });

我不知道為什么會有這個錯誤,也找不到解決方法。 你有主意嗎? 提前致謝。

對不起我的英語不好。

您的數據線是錯誤的。

它要么需要是:

data: '{ "id": "' + $(this).parent().parent().attr("data-id") + '", "elementCode":"' + $(this).val() + '", "userID": "' + $("#hidden_userID").val() + '"}',

要么:

data: { "id": $(this).parent().parent().attr("data-id"), "elementCode": $(this).val(), "userID": $("#hidden_userID").val()},

我個人會用一個外部變量來做

$(".selectProjectElement").change(function () {
  var data = { 
    id: $(this).parent().parent().attr("data-id"),
    elementCode: $(this).val(),
    userID: $("#hidden_userID").val()
  }
  $.ajax({
    ...
    data: JSON.stringify(data),
    ...
  });
});

暫無
暫無

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

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