I just can’t send request
This code perfectly works:
const data = new FormData()
data.append('file', event.target!.files![0])
const xhr = new XMLHttpRequest()
xhr.addEventListener('readystatechange', function () {
if (this.readyState === 4) {
console.log(this.responseText)
}
})
xhr.open('POST', 'http://localhost:9095/upload')
xhr.send(data)
but this do not, I executed both in the same project during the same event:
const formData = new FormData()
formData.append('file', event.target!.files![0])
const response = await axios({
method: 'post',
url: 'http://localhost:9095/upload',
data: formData,
headers: {
'Content-Type': 'multipart/form-data',
},
})
console.log(response.data)
ERROR:
ncaught (in promise) SyntaxError: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
at dispatchXhrRequest (axios.js?v=cf8614a3:1572:13)
at new Promise (<anonymous>)
at xhr (axios.js?v=cf8614a3:1557:10)
at Axios.dispatchRequest (axios.js?v=cf8614a3:2012:10)
at async Axios.request (axios.js?v=cf8614a3:2118:14)
at async handleFileUpload (fileButton.tsx:18:22)
at Axios.request (axios.js?v=cf8614a3:2122:41)
at async handleFileUpload (fileButton.tsx:18:22)
P.S. I use react ts + axios 1.7.3