javascript - Fetch API cannot load Error when fetches data from remote url -


i trying json data api - remote api. following javascript fetch data aforementioned api.

function getquote(){     //      fetch('https://api.forismatic.com/api/1.0/?method=getquote&format=json&lang=en')        .then((res) => res.json())     .then((data) => {        document.getelementbyid('name').innerhtml = '"' + data.quotetext + '"';       document.getelementbyid('description').innerhtml = 'by '+ data.quoteauthor;                 })      var element = document.getelementbyid('blue_bg');     element.style.background = getrandomcolor();    } 

in localhost works expected have enabled cors plugin in browser when comes live server getting following error.

fetch api cannot load https://api.forismatic.com/api/1.0/?method=getquote&format=json&lang=en. no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access. if opaque response serves needs, set request's mode 'no-cors' fetch resource cors disabled.

i tried fetch('https://api.forismatic.com/api/1.0/?method=getquote&format=json&lang=en',{mode: 'no-cors'}) error still persists.

any appreciated!


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -