【问题标题】:window.open works when at the start of the function but not at the endwindow.open 在函数开始时有效,但在结束时无效
【发布时间】: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


【解决方案1】:

刚刚从下面删除了假,我之前因为某种原因让它同步,但现在我需要它是异步的 yhttp.open('GET', 'url',false);

【讨论】:

    猜你喜欢
    • 2016-04-17
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-26
    • 2023-03-18
    • 1970-01-01
    相关资源
    最近更新 更多