MS Edge无法将从AJAX请求返回的Cookie保存在本地HTML文件中 [英] MS Edge won't save cookies returned from AJAX request in local HTML file

查看:37
本文介绍了MS Edge无法将从AJAX请求返回的Cookie保存在本地HTML文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在加载到Microsoft Edge中的本地文件的精简版本:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>

    <script>
      var url = "http://example.com"

      // Document is ready
      ready(function () {
        var xhr = new XMLHttpRequest();
        xhr.open('POST', url, true)
        xhr.withCredentials = true
        xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8")
        xhr.onload = function() {
          console.log('onload')
          console.log('Status: ' + xhr.status + ". " + xhr.statusText)
        }
        xhr.onerror = function(error) {
          console.log('onerror')
        }
        xhr.send()
      })

      // Hook for when the DOM has finished loading
      function ready(fn) {
        if (document.readyState !== 'loading') {
          fn()
        } else {
          document.addEventListener('DOMContentLoaded', fn)
        }
      }
    </script>
  </head>
  <body>
  </body>
</html>

使用file:///path/to/file.html可以很好地将其加载到浏览器中,并且请求成功返回。我遇到的问题是,响应应该在浏览器中设置一个cookie。它在Chrome、IE11、Firefox和Safari上运行良好,但在Edge上就不行了。

是否采取了某种安全措施来防止Edge从本地文件运行的Java脚本创建Cookie?如果是,为什么?

推荐答案

Microsoft Edge从不保存

  • 直接打开本地文件,例如file://C:/test/index.html
  • 包含下划线的域,例如test_a.mydomain.com

为了测试Cookie,必须创建一个工作环境,例如Localhost@xampp

这篇关于MS Edge无法将从AJAX请求返回的Cookie保存在本地HTML文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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