[英]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)
Hello, that's my error. 您好,这是我的错误。 I search on the web but other solved questions doesn't have the same code as me. 我在网上搜索,但其他已解决的问题与我的代码不同。
My code : 我的代码:
$(".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;
}
});
});
I don't know why I have this error and don't find a solution. 我不知道为什么会有这个错误,也找不到解决方法。 Have you an idea ? 你有主意吗? Thank's in advance. 提前致谢。
Sorry for my english. 对不起我的英语不好。
You data line is wrong. 您的数据线是错误的。
It either needs to be: 它要么需要是:
data: '{ "id": "' + $(this).parent().parent().attr("data-id") + '", "elementCode":"' + $(this).val() + '", "userID": "' + $("#hidden_userID").val() + '"}',
or: 要么:
data: { "id": $(this).parent().parent().attr("data-id"), "elementCode": $(this).val(), "userID": $("#hidden_userID").val()},
Personally I would do it with a variable outside 我个人会用一个外部变量来做
$(".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.