Guest User

Untitled

a guest
Sep 9th, 2015
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function post(){
  2.     if( $("#newPost").css("color") == "rgb(170, 170, 170)" ){
  3.         alertEmptyPost();
  4.         return;
  5.     }  
  6.     console.log("Loading uploaded files");
  7.     console.log($("#newPostForm")[0]);
  8.     var formData = new FormData($("#newPostForm")[0]);
  9.     console.log($("input[type=file]")[0].files[0]);
  10.     formData.append('file',$("input[type=file]")[0].files[0]);
  11.     $.ajax({
  12.         url: '/ajax/post',  //server script to process data
  13.         type: 'POST',
  14.         xhr: function() {  // custom xhr
  15.             myXhr = $.ajaxSettings.xhr();
  16.             if(myXhr.upload){ // if upload property exists
  17.                 myXhr.upload.addEventListener('progress', progressHandlingFunction, false); // progressbar
  18.             }  
  19.             return myXhr;
  20.         },  
  21.         //Ajax events
  22.         success: completeHandler = function(data) {
  23.             /*  
  24.             * workaround for crome browser // delete the fakepath
  25.             */
  26.             if(navigator.userAgent.indexOf('Chrome')) {
  27.                 var catchFile = $(":file").val().replace(/C:\\fakepath\\/i, '');
  28.             }  
  29.             else {
  30.                 var catchFile = $(":file").val();
  31.             }
  32. var writeFile = $(":file");
  33.             writeFile.html(writer(catchFile));
  34.             $("*setIdOfImageInHiddenInput*").val(data.logo_id);
  35.         },
  36.         error: errorHandler = function() {
  37.             alert("An error occured");
  38.         },
  39.         // Form data
  40.         data: formData,
  41.         //Options to tell JQuery not to process data or worry about content-type
  42.         cache: false,
  43.         contentType: false,
  44.         processData: false
  45.     }, 'json');
  46.     console.log("ajax");
  47. /*
  48.     $.ajax({
  49.         url: '/ajax/post',
  50.         type: 'POST',
  51.         'data':{
  52.             'post': $("#newPost").val(),
  53.             '_token': csrfToken
  54.         }
  55.     }).done(function(msg){
  56.         newComment(msg);
  57.     });
  58. */
  59.     console.log("post-ajax");
  60. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×