2

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]

1 Answer 1

1

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

Example

formData.append("file", file);
formData.append("tag", tag);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.