html2canvas js返回未定义的(承诺)未定义

时间:2018-09-27 22:37:42

标签: javascript

在这里已经提出了这个问题,但是没有给出足够的答案: html2canvas Uncaught (in promise) undefined

未命中(承诺)也被问了很多,但似乎没有一个能给我答案。显然我是错误地捕获了错误。

在这里,我要放置比该问题更多的代码,以更多地定义问题。

我正在尝试使用以下代码进行屏幕截图:

        function take_screenshot()
        {
          html2canvas(document.querySelector("#img_preview_text_container")).then(canvas => {
              var img = canvas.toDataURL()
              console.log('I took screenshot');
              $.post("save_screenshot.php", {data: img}, function (file){
                window.location.href =  "save_screenshot.php?file="+ file
              });
          });
        }

这将产生以下错误: 未捕获(承诺)未定义。根据几个这样的答案,我应该这样做:

function take_screenshot()
{
  html2canvas(document.querySelector("#img_preview_text_container"))
  .then(canvas => {
      var img = canvas.toDataURL()
      console.log('I took screenshot');
      $.post("save_screenshot.php", {data: img}, function (file){
        window.location.href =  "save_screenshot.php?file="+ file
      })
    .catch(e) {
      console.log(e);
    };
  });
}

在这里捕获e不会影响结果,我仍然可以 未捕获(承诺)未定义

有人可以让我知道我在做什么错吗?

0 个答案:

没有答案