-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddexact.html
59 lines (58 loc) · 1.71 KB
/
addexact.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html>
<head>
<title>url shortener</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<style type="text/css" media="screen">
body {
font: 2em/1.2em 'Open Sans', Helvetica, Verdana, sans-serif;
color: #444;
background: #F9F9F9;
text-align: center;
}
label {
display: block;
text-transform: uppercase;
font-weight: bold;
}
input,
input[type=submit] {
font: inherit;
}
</style>
</head>
<body>
<form action="/addexact" id="urlform" method="post" accept-charset="utf-8">
<p>
<label for="url">Url:</label>
<input type="text" name="url" value="" placeholder="http://example.org" id="url" />
</p>
<p>
<label for="uid">Uid:</label>
<input type="text" name="uid" value="" placeholder="text" id="uid" />
</p>
<p><input type="submit" value="Shorten →"></p>
<div id="error"></div>
</form>
<script>
var form = $('#urlform');
form.submit(function () {
$.ajax({
type: form.attr('method'),
url: form.attr('action') + '?url=' + $('#url').val() + '&uid=' + $('#uid').val(),
success: function (data) {
if (data) {
$('#urlform').replaceWith('<p id="shorten">'+
'Here is your shorter URL:<br/>'+
'<strong>http://' + location.host + '/' +
data[0].uid + '</strong></p>')
} else {
$('#error').html('<p><strong>Error: UID already taken</strong></p>');
}
}
});
return false;
});
</script>
</body>
</html>