未捕获的类型错误:无法读取的未定义的属性'与toLowerCase“ [英] Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
问题描述
我得到这个错误,它是由jQuery框架始发。 当我尝试加载的文件选择列表准备好我得到这个错误。 我似乎无法找到为什么我得到这个错误。
它工作的change事件,但我越来越想手动执行的功能,当错误。
未捕获的类型错误:无法读取的未定义的属性'与toLowerCase' - > jQuery的-2.1.1.js:7300
下面是code
$(文件)。就绪(函数(){
$(#CourseSelect)改变(loadTeachers);
loadTeachers();
});
功能loadTeachers(){
$阿贾克斯({
键入:GET,
网址:'/管理/ getTeachers /+ $(本).VAL()
数据类型:JSON,
缓存:假的,
成功:功能(数据){
$('#TeacherSelect')得到(0).options.length = 0。
$每个(数据,功能(我的老师){
VAR选项= $('<选项/>');
option.val(teacher.employeeId);
option.text(teacher.name);
$('#TeacherSelect)追加(可选)。
});
},
错误:函数(){
警报(错误而得到结果);
}
});
}
当你调用 loadTeachers()
在domready事件的背景下这个
不会是 #CourseSelect
元素。您可以使用 $代理
来强制此:
$(#CourseSelect)改变(loadTeachers);
$ .proxy(loadTeachers,$('#CourseSelect'))();
I'm getting this error and it is originating from jquery framework. When i try to load a select list on document ready i get this error. I can't seem to find why i'm getting this error.
It works for the change event, but i'm getting the error when trying to execute the function manually.
Uncaught TypeError: Cannot read property 'toLowerCase' of undefined -> jquery-2.1.1.js:7300
Here is the code
$(document).ready(function() {
$("#CourseSelect").change(loadTeachers);
loadTeachers();
});
function loadTeachers() {
$.ajax({
type: 'GET',
url: '/Manage/getTeachers/' + $(this).val(),
dataType: 'json',
cache: false,
success:function(data) {
$('#TeacherSelect').get(0).options.length = 0;
$.each(data, function(i, teacher) {
var option = $('<option />');
option.val(teacher.employeeId);
option.text(teacher.name);
$('#TeacherSelect').append(option);
});
},
error: function() {
alert("Error while getting results");
}
});
}
When you call loadTeachers()
on DOMReady the context of this
will not be the #CourseSelect
element. You can use $.proxy
to force this:
$("#CourseSelect").change(loadTeachers);
$.proxy(loadTeachers, $('#CourseSelect'))();
这篇关于未捕获的类型错误:无法读取的未定义的属性'与toLowerCase“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!