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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -