nurl/public/javascripts/shorten.js

26 lines
640 B
JavaScript
Raw Normal View History

2017-08-05 23:01:33 +00:00
function shorten(){
$.ajax({
url: '/api/v1/shorten',
type: 'POST',
dataType: 'JSON',
data: {url: $('#url-field').val()},
success: function(data){
console.log('data', data);
const $link = $('#link');
const resultHTML = `<a class="result" href="${data.shortUrl}">${data.shortUrl}</a>`;
$link.html(resultHTML);
$link.hide().fadeIn('slow');
2017-08-05 22:41:26 +00:00
2017-08-05 23:01:33 +00:00
}
});
}
2017-08-05 22:41:26 +00:00
2017-08-05 23:01:33 +00:00
$("#url-field").keyup(function(event){
if(event.keyCode === 13){
$("#btn-shorten").click();
}
});
2017-08-05 22:41:26 +00:00
2017-08-05 23:01:33 +00:00
$('#btn-shorten').on('click', function(){
shorten();
});