Use the Jquery ajax file upload

html:

  <input type="file" name="uploadFile" id="uploadFile">

jq:

$("#uploadFile").on("change", function() {

  var formData = new Formdata (); // create a form of the data type

  formData.append ($ ( "# uploadFile") [0] .files); // get the data uploaded file

  $.ajax({

    "url": "",

    "type": "",

    "ProcessData": false, // convert the data to an object, do not process data, so processData: false 

    "ContentType": false, // do not set the data type

    "XhrFields": {// This automatically sends a cookie to the browser in the background when requested

      withCredentials: true

    },

    "data": formData,

    success: function(data) {

      console.log(data)

    },

    error: function(data) {

    }

  })

})

Guess you like

Origin www.cnblogs.com/yuNotes/p/11165447.html