I'm currently trying to hammer together an image-uploading feature for a site I'm working on, and desire to do it using AJAX so as to not reload the page.
However, I've run into a snag. I'm basing myself off this question's answer, and in a previous project I got it to work. However, this time around the filedata does not seem to get stuffed into the formdata whatever I do. AJAX doesn't go through. Etc.
The jQuery looks like this:
$("body").on("change","#review_submit #imagefile",function() {
console.log(this.files[0]);
var formData = new FormData($("form#imageupload")[0]);
console.log(formData);
$.ajax({
url: "php/submit-imageupload.php",
type: "post",
success: completeHandler = function(data) {
if(data == "success") {
console.log("Success!");
}
},
error: function() {
console.log("Oops");
},
// Form data
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
}, 'json');
});
The console log winds up looking like:
File { size: 1407970, type: "image/png", name: "powerTreads.png", path: "", lastModifiedDate: Date 2014-08-08T21:49:19.477Z, mozFullPath: "E:\Pictures\powerTreads.png" }
FormData { }
Trying to browse the formdata there is no content to mention at all either.
The HTML looks like this: Image link of HTML
So can anyone see where I've gone wrong? :/