Answer the question
In order to leave comments, you need to log in
How to submit a form via ajax if enctype='multipart/form-data' is used?
I have a form. If you send it without Ajax, everything works fine. But when working through ajax, yii2 returns me an error:
PHP Fatal Error 'yii\base\ErrorException' with message 'Call to a member function saveAs() on a non-object
$('#user-file').on('submit', function(e){
e.preventDefault();
var url = $('#user-file').attr('action');
var data = $('#user-file').serialize();
$.ajax({
type: "POST",
url: url,
data: data,
});
});
Answer the question
In order to leave comments, you need to log in
$.ajax({
url: url,
type: 'POST',
data: new FormData( this ),
processData: false,
contentType: false,
success:function(src) {
//делаем что-то
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question