diff --git a/js/main.js b/js/main.js index ab66cdc..7651452 100644 --- a/js/main.js +++ b/js/main.js @@ -1,53 +1,45 @@ -'use strict' +var backend = 'https://ntut.com.tw'; -let backend = 'https://ntut.com.tw' - -const shortenUrl = async () => { - let shortCode = $('#urlBox .short-code')[0].value || null - let url = $('#urlBox .target-url')[0].value +function shortenUrl() { + var shortCode = $('#urlBox .short-code').val() || null; + var url = $('#urlBox .target-url').val(); if (!url) { - alert("URL is empty!") - return + alert("網址不能是空白的!"); + return; } - request({ shortCode, url }) - .done((res) => { - console.log(res) - - addNewRow(res) + request(shortCode, url) + .done(function (res) { + console.log(res); + addNewRow(res); }) - .fail((err) => { - console.log(err) - + .fail(function (err) { + console.log(err); if (err.status == 409) { - alert("This code has been used.") + alert("這個別名已經被使用了"); } else { - alert("Failed to establish connection.") + alert("無法建立連線,請稍後再試") } }) } -const addNewRow = (data) => { - let view = $('#urlBox .urls') +function addNewRow(data) { + var rowHtml = '
ntut.com.tw/' + data.shortCode + '
'; + rowHtml += '' + data.url + '
'; + rowHtml += 'ntut.com.tw/${data.shortCode}
-${data.url}
-