javascript - 我有错误 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),
...
});
});
推荐阅读
- scala - 如何检查 Spark 流中的批次是否为空(使用 socketTextStream 的字数)
- angular - 为什么我在使用 Nginx 设置 Angular 应用程序时得到 404
- android - 将变量传递给接口
- roku - ROKU:如何在同一个场景中添加 MarkupGrid 和 Rowlist?
- ruby-on-rails - 如果 _header.html.erb 显示 @current_user.name 的值,为什么 post_controller.rb 显示为 nil?
- c - 如何确定 char* 是否是 Windows 行结尾?
- sockets - socket 和 epoll 的 so_error 的行为
- angularjs - 如何在 Angularjs 中观察 2 个变量,其中 1 是位置路径?
- python - Python中的递归列表切片
- html - 是否需要安装 CSS3 插件?