如何中止/取消由Javascript代码引起的HTTP请求? [英] How can i abort/cancel a HTTP request caused by Javascript code?

查看:145
本文介绍了如何中止/取消由Javascript代码引起的HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这段代码可以从此网站

var imported = document.createElement('script');
imported.onload = function() {
  var str = document.querySelector("body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr > td:nth-child(3) > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(1)").innerHTML.length
  if (str <= 43) {
    var div = document.createElement("div");
    div.id = "divPage";
    var img = document.querySelector("body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr > td:nth-child(3) > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(1) > img");
    img.parentNode.insertBefore(div, img);
    div.appendChild(img);
  }

  html2canvas(document.querySelector("#divPage"), {
    onrendered: function(canvas) {
      var ctx = canvas.getContext("2d");
      var w = canvas.width;
      var h = canvas.height;
      ctx.fillStyle = "#FFF";
      ctx.fillRect(0, 0, w, h);
      var cap = document.querySelector("#divPage > img")
      ctx.drawImage(cap, 0, 0);
      var imgData = canvas.toDataURL('image/webp', 1.0);
      console.log(imgData);
    },
    useCORS: true,
    allowTaint: true,
    taintTest: false
  });
}

imported.src = 'https://pastebin.com/raw/dRap1YD8';
document.head.appendChild(imported);

此行将img请求发送到服务器,从而导致验证码值更改

This line send an img request to the server that cause changing of the captcha value

ctx.drawImage(cap,0,0);

我尝试使用XMLHttpRequest.abort(),但没有用

请注意,我正在使用Chrome控制台.感谢您的帮助!

Note that I'm using the Chrome console. I appreciate any help!

推荐答案

我不知道它是如何工作的,但是我在使用/p>/ORegMx/capito.png之后添加

I don't know how this worked but i add ?=0 after /ORegMx/capito.png using

document.querySelector("body > table.troisbords > tbody > tr > td > table > tbody > tr > td > div > blockquote > table > tbody > tr > td:nth-child(3) > table > tbody > tr:nth-child(2) > td > form > table > tbody > tr:nth-child(4) > td:nth-child(1) > img").src="/ORegMx/capito.png?=0"

这篇关于如何中止/取消由Javascript代码引起的HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆