【发布时间】:2020-10-14 21:02:10
【问题描述】:
我尝试每隔 x 秒调用一次此函数,但它返回此错误:
jquery.min.js:2 Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
..什么?
这是代码:
$(document).ready(function update() {
$.ajax({
url: 'config/db.php',
type: 'POST',
data: {
search: $(this).val()
},
success: function(result) {
$("#test1").html(result);
console.log('calling test1');
}
});
$.ajax({
url: 'config/db2.php',
type: 'POST',
data: {
search: $(this).val()
},
success: function(result) {
$("#test2").html(result);
console.log('calling test2');
}
});
setInterval(update, 1000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
有什么帮助吗?我查了这个错误,但我真的找不到任何我理解的东西。
【问题讨论】:
-
您发布的代码没有
toLowerCase -
在调用 val() 时,你想用
this引用什么? -
@Phix 是的,但那是执行sn-p时在控制台中记录的错误。
-
对,但没有可重现的例子谁知道。
-
您还在寻找@Phix 的更多可重现示例吗?执行问题中的代码会重现该错误。
标签: javascript jquery ajax setinterval