Get started with xdomain CDN

MIT licensed

Web API call from JS script, different origins, same-origin policy may block.

Tags:
  • cors
  • ie8
  • polyfill

Stable version

Copied!

How to start using xdomain CDN


// Create an instance of XDomainRequest
const xdr = new XDomainRequest();

// Set the URL and method for the request
xdr.open('GET', 'https://api.example.com/data');

// Set the responseType if needed
xdr.responseType = 'json';

// Set the onload and onerror event handlers
xdr.onload = function() {
  if (xdr.status === 200) {
    console.log('Request succeeded:', xdr.response);
  } else {
    console.log('Request failed:', xdr.statusText);
  }
};

xdr.onerror = function() {
  console.log('Error:', xdr.statusText);
};

// Load the XDomain library from the CDN
const script = document.createElement('script');
script.src = 'https://cdn.cdnhub.io/xdomain/0.8.2/xdomain.min.js';
script.onload = function() {
  // Send the request after the library is loaded
  xdr.send();
};
document.head.appendChild(script);
Copied!
Copied!
Copied!

All versions