Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. $("#gallery-image").change(function(){
  2. var formData = new FormData();
  3. formData.append('id', '{{$publication->id}}');
  4. for (var i=0; i<this.files.length; i++){
  5. formData.append('image'+i, this.files[i]);
  6. }
  7.  
  8. $.ajaxSetup({
  9. headers: {
  10. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  11. }
  12. });
  13.  
  14. jQuery.ajax({
  15. processData: false,
  16. contentType: false,
  17. url: "{{ url()->route('store_gallery') }}",
  18. method: 'post',
  19. data: formData,
  20. success: function(result){
  21. var newlyCreated = JSON.parse(result);
  22. console.log(newlyCreated);
  23. for (var i=0, f; f=newlyCreated[i]; i++){
  24. var image = '<div class="image-gall-prev" id="image_'+f.id+'" style="background-image:url('+f.gallery_img+')"><span onclick="removephoto(\'image_'+f.id+'\')"><i class="far fa-times-circle"></i></span></div>';
  25. $('.gallery-image-conatiner').append(image);
  26. $('.image-gall-prev').hide();
  27. $('.image-gall-prev').fadeIn(650);
  28. }
  29. }});
  30. });
  31.  
  32. function removephoto(full_id) {
  33. $('#'+full_id).remove();
  34.  
  35. var id = full_id.split("_")[1];
  36. var formData = new FormData();
  37. formData.append('id', id);
  38. console.log("/gallery/delete/"+id);
  39.  
  40. $.ajaxSetup({
  41. headers: {
  42. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  43. }
  44. });
  45.  
  46. jQuery.ajax({
  47. processData: false,
  48. contentType: false,
  49. url: "/gallery/delete/"+id,
  50. method: 'post',
  51. data: formData,
  52. success: function(result){
  53. console.log(result);
  54. }
  55. });
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement