Project

General

Profile

Feature #2939 ยป requestor.html

HTML page with javascript doing XMLHttpRequests to a webdav endoint running lighttpd/1.4.53 - katomaso, 2019-03-10 08:18

 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
	<title></title>
5
	<script>
6
		// try to send GET, POST, PUT to inspect CORS behaviour of the browser
7
		function sendSimpleXMLHttpRequest(method, filename) {
8
			console.log("Sending a simple " + method + " request");
9
			let xhr = new XMLHttpRequest();
10
			xhr.open(method, "https://peterka.me:82/" + filename);
11
			xhr.setRequestHeader("Authorization", "Basic Z3Vlc3Q6Z3Vlc3Q=");
12
			xhr.addEventListener("load", response => console.log("Response: ", response.currentTarget.responseText, "\n", response));
13
			xhr.addEventListener("error", response => console.log("Error: ", response));
14
			xhr.addEventListener("abort", response => console.log("Abort: ", response));
15
			xhr.send();
16
		}
17
	</script>
18
</head>
19
<body>
20
	<div>
21
		<strong>Existing file</strong><br/>
22
		<button onClick="sendSimpleXMLHttpRequest('GET', 'hello.txt')">GET request</button><br/>
23
		<button onClick="sendSimpleXMLHttpRequest('POST', 'hello.txt')">POST request</button><br/>
24
		<button onClick="sendSimpleXMLHttpRequest('PUT', 'hello.txt')">PUT request</button><br/>
25
		<form onSubmit="sendSimpleXMLHttpRequest(this.input['method'], 'hello.txt'); return false;">
26
			<input type="text" name="method"/>
27
			<input type="submit" value="... request"/>
28
		</form>
29
	</div>
30
	<br/>
31
	<div>
32
		<strong>Non-existing file</strong><br/>
33
		<button onClick="sendSimpleXMLHttpRequest('GET', 'nonexisting.txt')">GET request</button><br/>
34
		<button onClick="sendSimpleXMLHttpRequest('POST', 'nonexisting.txt')">POST request</button><br/>
35
		<button onClick="sendSimpleXMLHttpRequest('PUT', 'nonexisting.txt')">PUT request</button><br/>
36
		<form onSubmit="sendSimpleXMLHttpRequest(this.input['method'], 'nonexisting.txt'); return false;">
37
			<input type="text" name="method"/>
38
			<input type="submit" value="... request"/>
39
		</form>
40
	</div>
41
</body>
42
</html>
    (1-1/1)