2012-04-03 03:34:16 +02:00
|
|
|
<html>
|
2013-09-03 23:58:02 +02:00
|
|
|
<body bgcolor="white">
|
2012-04-03 03:34:16 +02:00
|
|
|
<script language="JavaScript">
|
|
|
|
function execXMLHttpRequest()
|
|
|
|
{
|
2017-11-09 20:00:47 +01:00
|
|
|
var url = document.getElementById("url").value;
|
|
|
|
var warningElement = document.getElementById("warning");
|
|
|
|
if (url.indexOf(location.origin) != 0) {
|
|
|
|
warningElement.innerHTML =
|
|
|
|
'For cross-origin requests to succeed the server must return CORS headers:' +
|
|
|
|
'<pre>Access-Control-Allow-Origin: ' + location.origin +
|
|
|
|
'<br/>Access-Control-Allow-Header: My-Custom-Header</pre>';
|
|
|
|
warningElement.style.display = 'block';
|
|
|
|
} else {
|
|
|
|
warningElement.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
2012-04-03 03:34:16 +02:00
|
|
|
xhr = new XMLHttpRequest();
|
2017-11-09 20:00:47 +01:00
|
|
|
xhr.open("GET", url, true);
|
2012-04-03 03:34:16 +02:00
|
|
|
xhr.setRequestHeader('My-Custom-Header', 'Some Value');
|
2014-11-21 22:49:52 +01:00
|
|
|
xhr.onload = function(e) {
|
|
|
|
if (xhr.readyState === 4) {
|
|
|
|
var value = "Status Code: "+xhr.status;
|
|
|
|
if (xhr.status === 200)
|
|
|
|
value += "\n\n"+xhr.responseText;
|
|
|
|
document.getElementById('ta').value = value;
|
|
|
|
}
|
|
|
|
}
|
2012-04-03 03:34:16 +02:00
|
|
|
xhr.send();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<form>
|
2023-09-26 22:12:32 +02:00
|
|
|
URL: <input type="text" id="url" value="https://tests/request">
|
2012-04-03 03:34:16 +02:00
|
|
|
<br/><input type="button" onclick="execXMLHttpRequest();" value="Execute XMLHttpRequest">
|
|
|
|
<br/><textarea rows="10" cols="40" id="ta"></textarea>
|
|
|
|
</form>
|
2017-11-09 20:00:47 +01:00
|
|
|
<div id="warning" style="display:none;font-weight:bold;"></div>
|
2012-04-03 03:34:16 +02:00
|
|
|
</body>
|
|
|
|
</html>
|