繁体   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