19 lines
517 B
JavaScript
19 lines
517 B
JavaScript
var form = document.getElementById('shorten-form');
|
|
var urlBox = form.elements[0];
|
|
var link = document.getElementById('link');
|
|
var shrBox = document.getElementById('shortened');
|
|
|
|
function displayShortenedUrl(response) {
|
|
link.textContent = response.data.url;
|
|
link.setAttribute(
|
|
'href', response.data.url
|
|
);
|
|
shrBox.style.opacity = '1';
|
|
urlBox.value = '';
|
|
}
|
|
form.addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
axios.post('/new', { url: urlBox.value }).then(displayShortenedUrl);
|
|
});
|