cors.html 681 B

123456789101112131415161718192021222324
  1. <!doctype html>
  2. <html>
  3. <head><title>running</title></head>
  4. <body><script>
  5. window.onload = function () {
  6. const params = new URL(document.location).searchParams;
  7. const api = params.get('api');
  8. if (api == "xhr") {
  9. const xhr = new XMLHttpRequest();
  10. xhr.open('get', params.get('url'), true);
  11. xhr.onload = e => document.title = 'load';
  12. xhr.onerror = e => document.title = 'error';
  13. xhr.onabort = e => document.title = 'abort';
  14. xhr.send();
  15. } else if (api == "fetch") {
  16. fetch(params.get('url')).then(
  17. e => document.title = 'load',
  18. e => document.title = 'error');
  19. } else {
  20. document.title = "unknown api";
  21. }
  22. };
  23. </script></body>
  24. </html>