I'm using Yii2 framework but in this specific situation I didn't use the activeform, so I'm using a normal input file like
<form id="formId">
<input type="text" name="txt" id="txt" />
<input type="file" name="nameFile" id="nameFile" />
<button type="submit">
</form>
in javascript, inside $(document).ready, I have
$("#formId").on( "submit", function( event ) {
event.preventDefault();
var formData = $(this).serialize();
$.ajax({
dataType: "json",
type: "POST",
data: formData,
url: "index.php?r=myControllerAction",
success: function (data) {
console.log(data);
},
error: function (jqXhr, textStatus, errorThrown) {
console.log(jqXhr);
}
});
});
In my controller, the $_FILES is empty. Someone knows why?