JSFiddle - React, Tailwind, and code Playground
by defeo
HTML
<p>Asking <a href='http://www.yahooapis.com'>query.yahooapis.com</a> about 'CORS'</p>
<textarea style='width:100%;height:10em' id='response-api'>
</textarea>
<p>Asking plain Yahoo about 'CORS'</p>
<textarea style='width:100%;height:10em' id='response-search'>
</textarea>
JavaScript
// Yahoo APIs
var XHR = new XMLHttpRequest();
XHR.open('GET', 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20answers.search%20where%20query%3D%22CORS%22&format=xml&diagnostics=true&callback=', true);
XHR.onreadystatechange = function() {
if (XHR.readyState == 4) {
document.getElementById('response-api').value = XHR.responseText;
}
}
setTimeout(function () { XHR.send(); }, 1000);
// Yahoo plain search
var XHR2 = new XMLHttpRequest();
XHR2.open('GET', 'http://search.yahoo.com/search?p=CORS', true);
XHR2.onreadystatechange = function() {
if (XHR2.readyState == 4) {
document.getElementById('response-search').value = XHR2.responseText || 'Bad luck!';
}
}
setTimeout(function () { XHR2.send(); }, 1000);