Uploading files via jQuery, object FormData is provided and no file name, GET request

后端 未结 4 2087
慢半拍i
慢半拍i 2021-01-13 01:27

I am using a jQuery script to upload files to a new page. It somehow works too, but the issue is that it sends the form data as object FormData.

Here i

4条回答
  •  佛祖请我去吃肉
    2021-01-13 01:58

    First get the Object

    First get the Object from HTML
    
     //HTML
     
    
     //JS
     var formData = new FormData()
     var file_obj = document.getElementById("file_name")
     formData.append('file_name', file_obj.files[0]);
     $.ajax({
        url: url,
        type: 'POST',
        data: formData,
        success: function (data) {
    
        },
        cache: false,
        contentType: false,
        processData: false
    })
    

提交回复
热议问题