This is a basic html starting page:
<html> <head> <meta charset="UTF-8"> <title>Stack Overflow Test Redirect</title> <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> </head> <body> Content of the document...... </body> </html>
Js part with JQuery:
$.ajax({ url: '/test/', type: 'GET', crossDomain: true, success: function() { alert("Success"); }, error: function() { alert('Failed!'); } });
and Vanilla JS example:
function makeRequest (method, url, done) { var xhr = new XMLHttpRequest(); xhr.open(method, url); // xhr.withCredentials = true; <--CORS ENABLED! xhr.onload = function () { done(null, xhr.response); }; xhr.onerror = function () { done(xhr.response); }; xhr.send(); } // And we'd call it as such: makeRequest('GET', '/test.com/', function (err, datums) { if (err) { throw err; } console.log(datums); });
Beware CORS. Hope it helps..