Saturday, 10 June 2017

javascript - Cross origin error in jquery.load()





I want to load html snippets into my html page with the following code:



       





In Firefox and Safari it works perfect, but in Chrome and IE Edge it gives me a cross origin request error:




XMLHttpRequest cannot load file:///../header.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.





Are there any workarounds for this error which are working in every of the named browsers?


Answer



You need an http server to request local files.



You can start one easily using python:



python -m http.server 8000

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...