首页 > 解决方案 > JavaScript 在 XHR 中的 this.response 中不起作用

问题描述

我今天对这段代码有两个问题:

document.addEventListener('click', function(event) {
  if (event.target.tagName !== "A" || !event.target.href) return;
  event.preventDefault();
  document.body.style.opacity = 0
  var res = new XMLHttpRequest();
  res.addEventListener("load", function() {
    document.querySelector('html').innerHTML =
      this.response;
  });
  res.open("GET", event.target.href);
  res.send();
});

如何插入动画document.body.style.opacity = 0;document.body.addEventListener("transitionend", function() { (现在它不起作用)

为什么不是this.response;不读JS的结果?(页面加载没有 JS)。

标签: javascriptcssxmlanimationxmlhttprequest

解决方案


推荐阅读