I develop with CakePHP and initially thought this problem was Cake-related; it wasn't. I've re-written the question to make the answer I received more widely applicable
I have a form
<form action"">
<fieldset>
<!---- bunch of fields----->
<input type="file" name="data[Upload][file]" id="UploadFile">
<button id="ajaxUploadSubmit"> Submit </button>
</fieldset>
</form>
And the submit function I've written looks like:
$( "#ajaxUploadSubmit" ).click(function() {
$.ajax({
url:"uploads/add",
data: $( "#UploadsAddForm" ).serialize()
}).done(function(responseText) {
alert(responseText);
})
.fail(function() {
alert('failxors');
})
});
But this line returns an empty array: $this->request->data
.
I'm only adding this answer so this question can be marked as answered; in fact thaJeztah answered this in the 3rd comment of Jai's answer: the problem, in this case, was that I should have been using FormData() instead of Serialize() as seen here: how to do file upload using jquery serialization
I think you are not stopping the form to submit:
Instead of
click
trysubmit
:try changing this:
to this one: