Answer the question
In order to leave comments, you need to log in
How to understand why data is not coming in POST?
I checked everything a thousand times, I still don’t see an error, help!
Controller:
public function actionSaveImage()
{
return json_encode($_POST);
}
<form id="myForm">
<input id="typeID" type="hidden" name="typeID" value="<?= Yii::$app->params['imageTypeCommentIssue'] ?>">
<input id="myFiles" name="myFiles" type="file" size="1"">
</form>
$('#myFiles').change(function (e) {
var formData = new FormData($('#myForm')[0]);
var url =[actionUrl];
$.ajax({
type: 'post',
url: url,
data: formData,
cache: false,
contentType: false,
processData: false,
xhr: function () {
var xhr = $.ajaxSettings.xhr(); // получаем объект XMLHttpRequest
xhr.upload.addEventListener('progress', function (evt) { // добавляем обработчик события progress (onprogress)
if (evt.lengthComputable) { // если известно количество байт
// высчитываем процент загруженного
var percentComplete = Math.ceil(evt.loaded / evt.total * 100);
// устанавливаем значение в атрибут value тега <progress>
// и это же значение альтернативным текстом для браузеров, не поддерживающих <progress>
// progressBar.val(percentComplete).text('Загружено ' + percentComplete + '%');
console.log('percentComplete: ', percentComplete);
$("#progressBar_1").css({
"width": percentComplete + "%",
});
}
}, false);
return xhr;
},
success: function (data) {
console.log('success');
data = JSON.parse(data);
console.log(data);
}
});
[]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question