0

This is extremely simple,

In a HTML file, inside of a <script> tag, I have

$.getScript("alert.js");

It doesn't work. alert.js being a basic alert(). What am I missing? The error codes read,

[Error] Failed to load resource: Origin null is not allowed by Access-Control-Allow-Origin. (alert.js, line 0)

and

[Error] XMLHttpRequest cannot load file:///Volumes/SSD2/kaely/kaely/alert.js?_=1471148162284. Origin null is not allowed by Access-Control-Allow-Origin.

I'm confused. Any help would be greatly appreciated. Thanks.

1 Answers1

0

Take a look at the answer in this post Origin null is not allowed by Access-Control-Allow-Origin

Your browser (I'm guessing Chrome?) is not allowing this to occur. You could either try testing this in another browser or setting up a local web server.

Community
  • 1
  • 1
kcdragon
  • 1,724
  • 1
  • 14
  • 23
  • Thanks. I'm running Safari so I assume this is a `webkit` issue. I don't understand how to add the feature and if it works when hosted as a public website. –  Aug 14 '16 at 04:36
  • 1
    You cannot load Ajax when running a website from a file, you have to be running a server – Ruan Mendes Aug 14 '16 at 21:10
  • @JuanMendes Oh, thanks. Isn't that annoying for local development? –  Aug 14 '16 at 21:47
  • 1
    Ajax works with local development. It just doesn't work when accessing an html page as a file with the "file://" protocol – kcdragon Aug 14 '16 at 22:30
  • Thanks @kcdragon. Without `file://` how else does one view a local webpage? –  Aug 17 '16 at 00:39