-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
27 lines (26 loc) · 1.01 KB
/
script.js
File metadata and controls
27 lines (26 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
function shortenUrl() {
var xhr = new XMLHttpRequest();
var url = document.getElementById("url").value;
var params = "url=" + encodeURIComponent(url);
xhr.open("POST", "shorten.php", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
document.getElementById("shortened-url").innerHTML = xhr.responseText;
}
};
xhr.send(params);
}
function retrieveUrlInfo() {
var xhr = new XMLHttpRequest();
var code = document.getElementById("shortcode").value;
var params = "code=" + encodeURIComponent(code);
xhr.open("POST", "retrieve.php", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
document.getElementById("url-info").innerHTML = xhr.responseText;
}
};
xhr.send(params);
}