function image_file_init() {
str = '
';
$('#content').html(str);
$('#result').html('');
$('#convert').click(function() {
image_file();
});
}
function image_url_init() {
str = '';
$('#content').html(str);
$('#result').html('');
$('#convert').click(function() {
image_url();
});
}
function image_file() {
var formData = new FormData();
formData.append('file', $('#file')[0].files[0]);
var url = '../servlet/image' + ($('#size').val() == '' ? '' : ('/size/' + $('#size').val()));
jQuery.ajax({
type : 'post',
url : url,
data : formData,
dataType : 'json',
cache : false,
contentType : false,
processData : false,
xhrFields : {
'withCredentials' : true
},
crossDomain : true,
success : function(json) {
$('#result').html(JSON.stringify(json, null, 4));
$('#image').html('
');
},
error : function(data) {
failure(data);
}
});
}
function image_url() {
var data = {
url : $('#url').val()
};
if ($('#size', '#content').val()) {
data.size = $('#size', '#content').val();
}
$.ajax({
type : 'post',
dataType : 'json',
url : '../jaxrs/image',
contentType : 'application/json; charset=utf-8',
data : JSON.stringify(data),
xhrFields : {
'withCredentials' : true
},
crossDomain : true
}).done(function(json) {
if (json.type == 'success') {
$('#result').html(JSON.stringify(json, null, 4));
$('#image', '#content').html('
');
} else {
failure(data);
}
}).fail(function(data) {
failure(data);
});
}