Having problem with XMLHttpRequest


#1

In codepen it’s ok,showing quotes when clicked on button, but when take this code to editor, doesnot work . shows this error ;
XMLHttpRequest cannot load https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=9&callback=. The ‘Access-Control-Allow-Origin’ header has a value ‘https://s.codepen.io’ that is not equal to the supplied origin. Origin ‘null’ is therefore not allowed access.
have used already https://crossorigin.me/ before api, gives error

See the Pen Random Quote by Eldar (@eldarm) on CodePen.


#2

This is something to do with running your site outside of a server. When you just “double-click” the file, it runs as file:/// instead of http://. Browsers have harsher rules when calling outside resources this way… which means CORS needs an extra push (if it will work at all). Research origin:* for possible solutions (one possible solution).

The good news is that as soon as you put it on a proper server again, it should work properly.


#3

did as it written there , added ‘callback=?’ ; doesnot work, gives other error
Refused to execute script fromhttps://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_…age]=0&callback=jQuery1111048909756994756104_1501786370757&_=1501786370758’ because its MIME type (‘application/json’) is not executable, and strict MIME type checking is enabled.