0

Im new to AJAX but good with PHP and doing a php/ajax project for a video upload. the AJAX side of things work fine but the file doesn't upload to the folder. below is the code sample. Thank you for your help in advance.

`

 <script type="text/javascript">
function uploadfile(){
var file = _('file1').files[0];
    alert(file.size);
    var formdata = new FormData();
    formdata.append("file1", file);
    var ajax = new XMLHttpRequest();
   // ajax.upload.addEventListener("progress", progressHandler,false);
   // ajax.addEventListener("load", completeHandler,false);
    //ajax.addEventListener("error", errorHandler,false);
    //ajax.addEventListener("abort", abortHandler,false);
    ajax.open("POST","process.php");
    ajax.send(formdata);
    }
         function completeHandler(){
            _('perc').innerHTML = "Upload Complete."; 
         }
         
         function errorHandler(){
            _('perc').innerHTML = "An error occured, Upload failed.";   
         }
         
         function abortHandler(){ 
             
         }
         
         function progressHandler(event){
             
             var perc = Math.round((event.loaded / event.total) * 100);
             _('progressbar').value = perc;
             _('perc').innerHTML = perc + "% uploaded";
             //_('status').innerHTML = "uploaded " + event.loaded + " bytes of " + event.total + "uploaded.";
         }
    
        function _(el){
            return document.getElementById(el);
        }
        
</script>`
S4NDM4N
  • 883
  • 1
  • 11
  • 23
  • 3
    You look at the console and the network tab – Masivuye Cokile Aug 22 '17 at 10:19
  • oh sorry, Here's the php code, the upload progress bar works fine, it reads the file name, size, etc. everything from the html to Ajax works as expected. I just added a redirect to the php script using a header/location function still it didnt redirect. is there another way to check if the AJAX is communicating with the PHP script? – Lucky Agbaroji Aug 22 '17 at 10:33

1 Answers1

-1

At the php side you can try printing all ajax data to an error log file (or, email yourself) using php function error_log(message,type,destination,headers); (more details about function here) to see if your request reaches to php script as expected.

You could also try copying the URL you are using in Ajax request and simply pasting it to address bar of your web browser and see what response do you get?

To verify response of php script after ajax request, print the response data in callback method of ajax.

prodev
  • 523
  • 4
  • 12