jQuery .load()失败 [英] jQuery .load() failure
本文介绍了jQuery .load()失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在以下链接中找到答案: 异步加载Div的内容
I'm trying to run an answer I found at the following link: Asynchronously Load the Contents of a Div
但是当我这样做的时候,我得到了我不太理解的错误.
But when I do, I get errors that I don't quite understand.
我的代码:
$(document).ready(function() {
$("#first").load(function() {
$("body").append($("<div></div>").attr({
id: "second"
}).text("Second"));
$("#second").load(function() {
$("body").append($("<div></div>").attr({
id: "third"
}).text("Third"));
});
});
});
<html>
<head>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-
3.2.1.min.js"></script>
</head>
<body>
<div id="#first">First</div>
</body>
</html>
我从Chrome回来的错误很广泛.但这是亮点:
The error I get back from Chrome is extensive. But here's the highlights:
Uncaught TypeError: a.indexOf is not a function
at r.fn.init.r.fn.load (jquery-3.2.1.min.js:4)
at HTMLDocument.<anonymous> (temp.html:6)
at j (jquery-3.2.1.min.js:2)
at k (jquery-3.2.1.min.js:2)
有什么想法吗?
推荐答案
此错误可能是由于jquery事件别名(例如.error
,.load
或.unload
)引起的.从jQuery 1.8
开始不推荐使用这些方法.您需要将它们替换为.on()
来注册侦听器.示例:
This error might be caused by jquery event aliases like .error
, .load
or .unload
. These are deprecated since jQuery 1.8
. You need to replace them with .on()
to register listeners instead. Example:
$(window).load(function(){
...
});
成为:
$(window).on('load', function(){
...
});
因此请尝试与.on()
这篇关于jQuery .load()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文