-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrieve.js
47 lines (39 loc) · 1.35 KB
/
retrieve.js
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
$(document).ready(function() {
$('#inpterror').html('').hide();
$('#loader').hide();
$('#retrbttn').click(function(e) {
e.preventDefault();
/* Clearing previous state before retrieving
new data. */
$('#titleretr').html('');
$('#imgretr').attr('src', '').hide();
$('#inpterror').html('').hide();
var baseUrl = '/retrieve/?url='
var siteurl = baseUrl + $('#url_input').val();
if (siteurl == baseUrl) {
/* Happens when text input field is empty. */
$('#inpterror').html('Enter a valid URL').show();
return
}
$('#loader').show();
$.ajax({
success: function(data) {
$('#loader').hide();
if (data.error == 'true') {
$('#inpterror').html(data.msg).show();
}
else {
/* Updates fields with information inside the
returned JSON. */
$('#imgretr').attr('src', data.imgsrc).show();
$('#titleretr').html(data.title);
}
},
error: function(data) {
$('#loader').hide();
$('#inpterror').html('An error occurred').show();
},
url: siteurl
});
});
});