kesenai

Untitled

Oct 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. function uploadImage() {
  2.  
  3. $(document).on('change', 'input[type=file]', function () {
  4. console.log('uploading image...');
  5.  
  6. $("#image").replaceWith("<img src='/img/loading.gif' class='img-thumbnail' style='width: 450px;'>");
  7.  
  8. setTimeout(function () {
  9. var url = $('form').data('url');
  10. var type = $('form').data('type');
  11. var fd = new FormData();
  12. fd.append('image', $('#ErikaNowhereImageUploadWidgetFile')[0].files[0]);
  13.  
  14. $.ajax({
  15. type: "POST",
  16. url: url,
  17. data: fd,
  18. processData: false,
  19. contentType: false,
  20. cache: false,
  21. success: function (response) {
  22. if (response) {
  23. var json_obj = $.parseJSON(response);
  24. for (var i in json_obj) {
  25. if (json_obj[i].status == 'ok') {
  26. if (type == 'full') {
  27. $("#ErikaNowhereImageUploadWidgetForm").replaceWith("<img src='/upload/image/" + json_obj[i].id + "' class='img-thumbnail' style='width: 450px;'>");
  28. } else {
  29. $("#ErikaNowhereImageUploadWidgetForm").replaceWith("<img src='/upload/image/" + type + "/" + json_obj[i].id + "' class='img-thumbnail' style='width: 450px;'>");
  30. }
  31. $("#form_imageId").val(json_obj[i].id);
  32. } else {
  33. alert('upload error');
  34. }
  35. }
  36. }
  37. }
  38. });
  39. }, 1000);
  40. });
  41. }
  42.  
  43. $(document).ready(function () {
  44. uploadImage();
  45. });
Add Comment
Please, Sign In to add comment