Q
Q
qu1kgg2020-01-09 17:04:24
AJAX
qu1kgg, 2020-01-09 17:04:24

FILES ajax empty variable coming, why?

An empty file arrives, although everything worked a couple of days ago:

function prov() {
   var data = new FormData($('#prov')[0]);
    $.ajax({
      type: "POST",
      url: "/engine/prov.php",
      data: data,
      contentType: false,
      processData: false,
     success: function(response) {
                    console.log(response)
                }           
    });
  }

<form method="post" id="prov" action="" enctype="multipart/form-data">
          <div class="input-wrapper">
            <input id="provtxt" type="text" name="provtxt">
            <label for="img"><i class="fa fa-paperclip" aria-hidden="true"></i></label>
            <input id="img" type="file" name="img">
          
          </div>
          
        </form>
          <button onclick="prov();" class="send-btn">ОТПРАВИТЬ</button>

What could be the problem??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Maltsev, 2020-01-09
@qu1kgg

var $input = $("#prov");
    var fd = new FormData;

    fd.append('img', $input.prop('files')[0]);

    $.ajax({
        url: '/engine/prov.php,
        data: fd,
        processData: false,
        contentType: false,
        type: 'POST',
        success: function (data) {
            alert(data);
        }
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question