Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function uploadImage() {
- $(document).on('change', 'input[type=file]', function () {
- console.log('uploading image...');
- $("#image").replaceWith("<img src='/img/loading.gif' class='img-thumbnail' style='width: 450px;'>");
- setTimeout(function () {
- var url = $('form').data('url');
- var type = $('form').data('type');
- var fd = new FormData();
- fd.append('image', $('#ErikaNowhereImageUploadWidgetFile')[0].files[0]);
- $.ajax({
- type: "POST",
- url: url,
- data: fd,
- processData: false,
- contentType: false,
- cache: false,
- success: function (response) {
- if (response) {
- var json_obj = $.parseJSON(response);
- for (var i in json_obj) {
- if (json_obj[i].status == 'ok') {
- if (type == 'full') {
- $("#ErikaNowhereImageUploadWidgetForm").replaceWith("<img src='/upload/image/" + json_obj[i].id + "' class='img-thumbnail' style='width: 450px;'>");
- } else {
- $("#ErikaNowhereImageUploadWidgetForm").replaceWith("<img src='/upload/image/" + type + "/" + json_obj[i].id + "' class='img-thumbnail' style='width: 450px;'>");
- }
- $("#form_imageId").val(json_obj[i].id);
- } else {
- alert('upload error');
- }
- }
- }
- }
- });
- }, 1000);
- });
- }
- $(document).ready(function () {
- uploadImage();
- });
Add Comment
Please, Sign In to add comment