1

I'm building a website and the page loads a navbar and some other resources with Jquery .load() function (as seen in code below).

<script>
        $(function () {
            $("#navbar-placeholder").load("subpage_navbar.html");
        });
</script>

When viewing the .html files locally on my computer in safari 5 everything works fine, and it used to work fine in safari 11, but now when I try to open the file I get an error:

XMLHttpRequest cannot load file:///... Preflight response is not successful

Are there any preferences I need to change in safari for this to work like it used to?

Jasper
  • 23
  • 2
  • 6

1 Answers1

2

XMLHttpRequest dont work with file protocol only with http, data, chrome, chrome-extension, https.

you need to host your file or use something like this link bellow to allow this.

Allow Google Chrome to use XMLHttpRequest to load a URL from a local file

In Safari 11 file protocol access are limited.

[CORS and cross origin access from file:// are now blocked unless Disable Local File Restrictions is selected from the Develop menu.]

Andrea Perelli
  • 156
  • 2
  • 3
  • 14
Ciro Spaciari
  • 630
  • 5
  • 10
  • but I was able to get it to work before with file protocol, and it still works in safari 5. The network log shows the request as a GET method, text/html type, (pending) status. – Jasper Dec 15 '17 at 22:46
  • "CORS and cross origin access from file:// are now blocked unless Disable Local File Restrictions is selected from the Develop menu." [See more here](https://developer.apple.com/library/content/releasenotes/General/WhatsNewInSafari/Safari_11_0/Safari_11_0.html) – Ciro Spaciari Dec 15 '17 at 22:54
  • ok after checking the Disable Local File Restrictions in the develop menu everything works now. Thank you! – Jasper Dec 15 '17 at 23:34