Web客户端接入 4CAF50; color: fff; border: none; borderradius: 5px; cursor: pointer; } / 登录 立即点击验证 登录 // 定义验证码触发事件 window.onload function () { var ticket ""; var type "1"; document.getElementById("CaptchaId").onclick function (event) { try { var captcha sliderCaptcha({ event, / 成功回调 回调入参 verify: { isVerify, // 成功失败 code, //code code0表示成功,可以获取ticket,1的话是验证数据格式有误,2是验证失败,3是验证动作超时,4是验证码版本不对ll, ticket //ticket } / onSuccess: function (verify) { //成功事件 ticket verify.ticket; type verify.type; const ele document.querySelector(" CaptchaId"); ele.classList.add("btcaptchasuccess"); ele.innerHTML 验证成功; }, / 失败回调 / onFail: function (verify) { console.log(verify); }, }); } catch (error) { console.log(error); } }; function submit() { // do 提交接口携带 ticket console.log("使用XMLHttpRequest发起请求"); var xhr new XMLHttpRequest(); xhr.open("GET", "/test", true); // xhr.open('GET', ' true); //设置请求头 xhr.setRequestHeader("ticket", ticket); xhr.withCredentials true; //携带cookie xhr.send(); //请求成功完成时触发。 xhr.onload function () { if (xhr.readyState xhr.DONE) { if (xhr.status 200) { console.log("响应内容:"); console.log(xhr.response); console.log(xhr.responseText); console.log(""); //获取响应头 var headers xhr.getAllResponseHeaders(); console.log("响应头:"); console.log(headers); console.log(""); } else { console.log(xhr.status); } } }; } document.getElementById("submit").onclick function () { submit(); }; }; 登陆