I
I
iFortunes2018-07-11 17:53:13
AJAX
iFortunes, 2018-07-11 17:53:13

I send data via ajax and get an object on the server, how to overcome it?

Actually, this is the first time I've encountered this.

file = new FormData();
        file.append('file', files[0]['name']);
        file.append('url', $('input[name=\'url-yml\']').val());
        file.append('data', $('#yml-form').serializeArray());
        console.log(file);
        $.ajax({
            url: '<?php echo htmlspecialchars_decode($upload_yml); ?>',
            type: 'post',
            //data: {'url': url, 'data': data},
            cache: false,
            processData: false, // Не обрабатываем файлы (Don't process the files)
            contentType: false, // Так jQuery скажет серверу что это строковой запрос
            data: file,
            success: function (json) {
                console.log(json);
                
                if (json['success']) {
                   
                }
            },
            error: function (xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });

The server receives: "[object Object],[object Object]" instead of an array of fields.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question