A
A
Alexander Ampleev2018-05-26 18:24:27
JavaScript
Alexander Ampleev, 2018-05-26 18:24:27

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);
     

    }

View:
<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>

JS:
$('#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);

        
        }

    });

an empty array is returned again ..
in the answer []
you need typeID

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ampleev, 2018-05-26
@Ampleev

found form nested in form

T
ThunderCat, 2018-05-26
@ThunderCat

return echo json_encode($_POST);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question