I am using jQuery to do AJAX uploading with additional data. The Stackoverflow code I am following it this one How can I upload files asynchronously? and the code I am using is the following:
var formData = new FormData($('form')[0]);
$.ajax({
type: "POST",
url: "ajax/register.php",
dataType: "text",
data: {
name: $("#name").val(),
city: $("#city").val(),
image: formData
},
success: function(text) {
if(text == "data ok pic ok") { window.location = "reg3.php"; }
else { errorMessage(text); }
},
cache: false,
contentType: false,
processData: false
});
});
The problem is that, if I remove the file-related codes, such as
var formData = new FormData($('form')[0]);
image: formData
cache: false,
contentType: false,
processData: false
then the code works and I can send other data, too like "name" and "city". When I put back in the file-related code, it stops working, no errors in the console and no action from the PHP script on the server (like it did not receive the other relevant data)
Any ideas?
Thanks in advance.