0👍
You are calling a then after the fetch’s then which does not exists.
You can use arrow functions at then for accessing the response variable you got from the request
let data = new FormData()
data.append('name', 'hey')
fetch('http://homestead.test/api/customers', {
method: 'POST',
headers: {
'Content-type': 'multipart/form-data'
},
body: data
})
.then((response) => {
// now you can access response here
console.log(response)
})
- [Vuejs]-How to create filters for a Vue component
- [Vuejs]-Correct NodeJS server for Vue.js application
0👍
I think the problem may be with the content header type it should
{
Content-type: 'application/json'
}
And also try to send the data with:
body :JSON.stringify(data)
- [Vuejs]-Uncaught ReferenceError: Vue is not defined – but only sometimes
- [Vuejs]-Http request 500 internal server error on Axios put
0👍
I do not understand why FormData is empty, but all requests with JSON body works.
let data = new FormData()
data.append('name', 'hey')
let json = JSON.stringify(Object.fromEntries(data));;
fetch('http://homestead.test/api/customers', {
method: 'POST',
headers: {
'Content-type': 'application/json'
},
body: data
})
.then((response) => response.json())
.then((response) => {
console.log(response)
})
- [Vuejs]-Render vue js build into Node js and Hapi js project
- [Vuejs]-VueJs / @Babel polyfill not working on IE11 v. 11.371 / prod build
Source:stackexchange.com