ajax 如何更新DOM

打错了节点的id了晕
Uncaught TypeError: Cannot read property 'innerHTML' of null
<script type="text/javascript">
function getmore(){
var p = document.getElementById("result").innerHTML;
alert(p)
var xhr = new XMLHttpRequest();
xhr.open('GET', '{{url_for('api.get_posts')}}',true);
xhr.onreadystatechange = function(){

if(xhr.readyState ==4 && xhr.status == 200){
  // alert('success');
  document.getElementById("result").innerHTML = xhr.responseText;
  var data = JSON.parse(xhr.responseText);
  if(data){
    console.log(xhr.responseText);
    p = "fff";
  }
  else {
    console.log('nothing');
  }
}
else{
  console.log('ajax error');
}

}
xhr.send();
}
</script>

阅读 3.3k
1 个回答

Uncaught TypeError: Cannot read property 'innerHTML' of null

这就不是 AJAX 的问题了吧

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题