jquery/js 错误 - DOM 错误:DOM 异常 8 - 当我 .html 任何变量时
当我尝试执行一段非常简单的代码时,我收到了 DOM 错误:DOM 异常 8。我已经执行过类似的处决一百万次,我很困惑问题是什么。
我的代码:
$.post('/dataHandlers/return_stats.php', function(data) {
$('#u').html(data['username']);
var health = data['health'];
$('#health_display').html(health);
$('#energy_display').html(data['energy']);
$('#money_display').html(data['money']);
$('#intelligence_display').html(data['intelligence']);
$('#strength_display').html(data['strength']);
$('#sidebar').find('#level_display').html(data['level']);
}, 'json');
HTML:
<div id='sidebar'>
<div id ="health_display" class="stats_right"></div>
</div>
如果我尝试 .html 不是变量的东西,它就会起作用。每当我 .html 任何变量时,我都会收到该错误。
有人知道这是关于什么的吗?提前致谢。
I'm receiving a DOM Error: DOM Exception 8 when I try to execute a very simple piece of code. Ive done similar executions a million times and I'm very confused what the problem is.
My Code:
$.post('/dataHandlers/return_stats.php', function(data) {
$('#u').html(data['username']);
var health = data['health'];
$('#health_display').html(health);
$('#energy_display').html(data['energy']);
$('#money_display').html(data['money']);
$('#intelligence_display').html(data['intelligence']);
$('#strength_display').html(data['strength']);
$('#sidebar').find('#level_display').html(data['level']);
}, 'json');
HTML:
<div id='sidebar'>
<div id ="health_display" class="stats_right"></div>
</div>
If I try and .html something that isn't a variable, it works. Whenever I .html any variable whatsoever, I get that error.
Anyone know what this is about? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保将字符串传递给
html()
;例如,如果这些是数组,您可能会收到类似的 DOM 错误。即,
jQuery("a").html([1,2])
抛出相同的错误;你可能有类型问题。如果它们是数组,我不会感到惊讶;如果您
alert([1,2])
,它只会提醒1,2
,因此一切都会显示正常。Be sure you're passing a string to
html()
; if, for example, those are arrays, you can get DOM errors like that.ie,
jQuery("a").html([1,2])
throws the same error; you likely have a type problem.I wouldn't be surprised if it they're arrays; if you
alert([1,2])
, it just alerts1,2
, so everything would appear normal.我见过类似的问题,输出被
.html()
奇怪地解释。您是否尝试使用
.text()
并看看发生了什么?I've seen a similar problem with the output being interpreted strangely by
.html()
.Did you try using
.text()
and seeing what happened?