JSFiddle - React, Tailwind, and code Playground

HTML

<span id="id1"></span>

JavaScript

var WikipediaCORS=
	{
	setMessage:function(msg)
		{
		var span=document.getElementById("id1");
		span.appendChild(document.createTextNode(msg));
		},
	// Create the XHR object.
	createCORSRequest:function(url)
		{
		var xhr = new XMLHttpRequest();


		if ("withCredentials" in xhr)
			{
			xhr.open("GET", url, true);
			}
		else if (typeof XDomainRequest != "undefined")
			{
			xhr = new XDomainRequest();
			xhr.open(method, url);
			}
		else
			{
			return null;
			}
		xhr.setRequestHeader("Access-Control-Allow-Credentials", "true");
		xhr.setRequestHeader("Access-Control-Allow-Origin","*");
		return xhr;
		},
	init:function()
		{
		var _this=this;
  		var url = 'http://en.wikipedia.org/w/api.php?action=opensearch&search=Javascript&format=json';
  		var xhr = this.createCORSRequest(url);
 		if (!xhr)
 		 	{
    			this.setMessage('CORS not supported');
    			return;
  			}

  		xhr.onload = function()
  			{
    			_this.setMessage(xhr.responseText);
  			};
  		xhr.onerror = function()
  			{
    			_this.setMessage('Woops, there was an error making the request.');
  			};
  		xhr.send();
		}
	};


WikipediaCORS.init();