Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to use html5 formData along with jquery ajax to perform ajax file upload (Single File), but this not working. Below is my js code

//I tried this but return Cannot read property '0' of undefined
  var file = $folderID.find('.add-file').files[0];  

//I also tried this no error return, no file uploaded, no data inserted to db.
var file = $folderID.find('.add-file')[0].files[0];
  var formData = new FormData();
  formData.append("file", file);

var tag = $folderID.find('.hidden-tag').val();

$.ajax({
    type: 'POST',
    contentType:false,
    processData:false,
    url: baseUrl + 'folder/post',
    data: {'file':formData ,'tag':tag},
    error: function (request, status, error) {
        alert(request.responseText);
      }
  });

Note: the php file is working perfectly without using ajax.

Update headers return 302 not found and request payload [object] [object]

share|improve this question
add comment (requires an account with 50 reputation)

1 Answer

up vote 1 down vote accepted

Fixed, I moved all the jquery .val() to formdata.

Example

formData.append("file", file);
formData.append("tag", tag);
share|improve this answer
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.