MS Edge won't save cookies returned from AJAX request in local HTML file

回眸只為那壹抹淺笑 提交于 2019-12-06 07:47:04

问题


The following is a stripped down version of a local file that I'm loading into 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>

Loading it into the browser works great using file:///path/to/file.html and the request returns successfully. The problem that I'm running into is that the response is supposed to set a cookie in the browser. It works perfectly on Chrome, IE11, Firefox and Safari, but not on Edge.

Is there some sort of security measure in place preventing Edge from creating cookies from JavaScript that is run from a local file? If so, why?

来源:https://stackoverflow.com/questions/34997121/ms-edge-wont-save-cookies-returned-from-ajax-request-in-local-html-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!