html中的布局是這樣的
<div class="box">
<div class="user_box">
<div class="user_head"><img src="" width="50" height="50" id="imge"></div>
<div class="user_name" id="name"><span class="user_brief" id="idinfo"></span></div>
<div class="user_id" id="iddentity"></div>
</div>
</div>
ajax請求成功返回的數據賦值給span標簽,代碼如下:
success : function(data) {
document.getElementById("imge").src=""+data.body.portrait+"";
document.getElementById("name").innerHTML=""+data.body.nickname+"";
document.getElementById("idinfo").innerHTML=""+data.body.nickname+"";
}
我賦值一樣的數據都不行,提示Cannot set property 'innerHTML' of null
document.getElementById("name").innerHTML=""+data.body.nickname+"";你這句已經將idinfo這個span對象刪除了,下一句就報錯了。。去掉這句
除非你的nickname包含id為idinfo的html代碼