【发布时间】:2020-10-20 12:04:39
【问题描述】:
window.open 在函数开始时有效,但在结束时无效。这个有效
render = function() {
window.open("https://xxxx=singhi");
var yhttp = new XMLHttpRequest();
yhttp.open('GET', 'url', false);
yhttp.setRequestHeader('Authorization', 'AR-JWT ' + res);
yhttp.setRequestHeader('Content-Type', 'application/json');
yhttp.send();
const tit = yhttp.responseText;
document.write(tit);
document.write(tit.entries[0].values["Remedy Login ID"]);
remedyid=tit.entries[0].values["Remedy Login ID"];
};
这个没有
render = function() {
var yhttp = new XMLHttpRequest();
yhttp.open('GET', 'url', false);
yhttp.setRequestHeader('Authorization', 'AR-JWT ' + res);
yhttp.setRequestHeader('Content-Type', 'application/json');
yhttp.send();
const tit=yhttp.responseText;
document.write(tit);
remedyid = tit.entries[0].values["Remedy Login ID"];
window.open("https://xxxx=singhi");
};
【问题讨论】:
-
考虑使用
fetch而不是XMLHttpRequest? ---另外,请您添加“这个没有”的意思吗?你期望会发生什么?现在发生了什么? -
window.open 在第一种情况下打开 url,但在第二种情况下不打开,它被放置在函数的末尾,很奇怪
-
浏览器控制台有错误吗?请确保示例为minimal reproducible examples。
-
控制台没有错误
-
那么您能确保我们可以运行您的示例吗?有很多缺失的东西,其中大部分可能无关紧要。
标签: javascript ajax asynchronous xmlhttprequest window