:cookie: 387 | @kbaig |http://www.freecodecamp.com/kbaig
:cookie: 388 | @kbaig |http://www.freecodecamp.com/kbaig
After trying to call the api when a user type in the location, I get this error:
Failed to load https://autocomplete.wunderground.com/aq?query=San%20F&c=US: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access.
Anyone know how to solve this?
:cookie: 187 | @dennisloska |http://www.freecodecamp.com/dennisloska
var main = document.getElementsByTagName("main")[0];
/*
* Method not used but works, if forismatic would enable CORS-compatibility :(
*/
/*
function getQuote() {
var xhttp = new XMLHttpRequest();
xhttp.open("POST",
"https://api.forismatic.com/api/1.0/?method=getQuote&key=457653&format=json&lang=en",
true);
if ('withCredentials' in xhttp) {
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status ==
200) {
var quote = JSON.parse(this.responseText);
document.getElementById("quoteField").innerHTML = quote.quoteText + "</br></br>" +
quote.quoteAuthor;
} else {
document.getElementById("quoteField").innerHTML =
"Sorry, something went wrong there." + "</br></br>" + "Dennis, Web-Rookie"
}
};
xhttp.send();
}
}
*/
//dynamically loads in a new script-tag, when the quote-button is clicked
function createJSONPScriptTag() {
//This does not work for some reason with THIS API, so I have to reload the page...
/*
var script_element = document.createElement('script'),
url = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_jsonp=parseQuote"
script_element.setAttribute('src', url);
document.head.appendChild(script_element);
*/
location.reload();
}
https://dennisloska.github.io/QuoteMashine/
var script_element = document.createElement('script'),
url = "https://quotesondesign.com/wp-json/posts?filter[orderby]=rand&filter[posts_per_page]=1&_jsonp=parseQuote"
script_element.setAttribute('src', url);
document.head.appendChild(script_element);
location.reload();
try to hack it somehow like this maybe it will work :smile:
:cookie: 686 | @korzo |http://www.freecodecamp.com/korzo