There is jquery code with two post requests, the first processes the form, the second files. How to make everything go in one post request?

//Π‘ΠΎΡ…Ρ€Π°Π½Π΅Π½ΠΈΠ΅ страницы $j('.save').click(function (e) { var cont = $j('.edit').serialize(); $j.ajax({ type: 'POST', url: 'edit.php', dataType: 'html', data: cont, success: function (response) { $j(".result-files-upload").html(response); // Π€Π°ΠΉΠ» Π·Π°Π³Ρ€ΡƒΠΆΠ΅Π½ $j(".result-files-upload").fadeIn(); setTimeout(function () { $j(".result-files-upload").fadeOut() }, 1500); }, error: function (xhr, str) { alert('Π’ΠΎΠ·Π½ΠΈΠΊΠ»Π° ошибка: ' + xhr.responseCode); } }); var inp = $j('input[name="editimg"]').val(); if (inp == "yes") { var formData = new FormData($j(".sendfileform")[0]); $j.ajax({ url: 'edit.php', //ΠΊΡƒΠ΄Π° ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ Π΄Π°Π½Π½Ρ‹Π΅ type: 'POST', data: formData, cache: false, dataType: 'html', processData: false, contentType: false, success: function (response) { $j(".result-files-upload").html(response); // Π€Π°ΠΉΠ» Π·Π°Π³Ρ€ΡƒΠΆΠ΅Π½ $j(".result-files-upload").fadeIn(); setTimeout(function () { $j(".result-files-upload").fadeOut() }, 1500); } }); } }); 

    1 answer 1

    Understood, just combined requests

     var formData = new FormData($j(".edit")[0]); $j.ajax({ type: 'POST', url: 'edit.php', dataType: 'html', data: formData, processData: false, contentType: false, success: function (response) { $j(".result-files-upload").html(response); // Π€Π°ΠΉΠ» Π·Π°Π³Ρ€ΡƒΠΆΠ΅Π½ $j(".result-files-upload").fadeIn(); setTimeout(function () { $j(".result-files-upload").fadeOut() }, 1500); }, error: function (xhr, str) { alert('Π’ΠΎΠ·Π½ΠΈΠΊΠ»Π° ошибка: ' + xhr.responseCode); } });