如何使用javascript从请求-响应更新URL?

如何使用javascript从请求-响应更新URL?,javascript,Javascript,我有一个JavaScript函数,它正试图模拟表单提交 function fopen() { var xhr = new XMLHttpRequest(); xhr.open("POST", open_url, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.send(JSON.stringify({ create: 0, jobtype: job

我有一个JavaScript函数,它正试图模拟表单提交

function fopen() {
  var xhr = new XMLHttpRequest();
  xhr.open("POST", open_url, true);
  xhr.setRequestHeader('Content-Type', 'application/json');
  xhr.send(JSON.stringify({
      create: 0,
      jobtype: jobtype,
      name: document.getElementById("file-selector").value
  }));
  xhr.onreadystatechange = function() {
    if (xhr.readyState == XMLHttpRequest.DONE) {
        document.write(xhr.responseText);
    }
    else {
      console.log('ErR0r')
    }
  }
}

行为几乎相同,但响应后不会更新URL。我看到有一个xhr.responseURL属性,但是我如何才能在地址栏中显示它呢?是否有一个表单提交的完整JavaScript实现可以让我参考,以便尽可能保持相似?

要更改页面的URL,请设置
window.location.href