javascript - js upload file - No files were uploaded -


i uploading image file on server-side , script give error

error: "no files uploaded."

<form enctype="multipart/form-data" method="post">   <input name="file" type="file"/>   <input class="btn btn-warning" type="button" value="upload"/> </form> 

js code

$(':button').click(function () {     var formdata = new formdata($('form'));     $.ajax({         url: "/files/create",         type: 'post',         success: completehandler,         data: formdata,         cache: false,         contenttype: false,         processdata: false      });     console.log(formdata); });  function completehandler() {     console.log("complete success"); } 

have idea? can connected?

try this:

//html part  <form enctype="multipart/form-data" method="post">     <input name="file" type="file"/>     <input class="btn btn-warning" type="submit" value="upload"/> </form>  //js part <script> $('form').submit(function (e) {     e.preventdefault();     var formdata = new formdata($(this)[0]);     $.ajax({        url: '/files/create',        type: 'post',        data: formdata,        async: false,        cache: false,        contenttype: false,        enctype: 'multipart/form-data',        processdata: false,        success: function (response) {          alert(response);        }     });     return false; });  </script> 

php part in create.php

<?php     if(isset($_files['file'])){       print_r($_files);     } ?> 

Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -