Home > front end >  Js fetch promise object to return into a json object but return promise object
Js fetch promise object to return into a json object but return promise object

Time:11-06

 const upload=async (url, formData)=& gt; {
The fetch (url, {
Method: "POST",
Headers: {
'the content-type' : 'multipart/form - data',
},
Body: formData,
})
Then (response=& gt; (response. Json ()))
The catch (error=& gt; {
console.log(error);
});
};


Want to return the value of a json object

CodePudding user response:

Const upload=async (url, formData)=& gt; {
Return await the fetch (url, {
Method: "POST",
Headers: {
'the content-type' : 'multipart/form - data',
},
Body: formData,
(}). Then the response=& gt; (response. Json ()))
};
The upload ('../FE/2018/testdata/abortcontroller. Json '{})
Then (the console. The log);

CodePudding user response:

Retutrn upload is not a promise???????
  • Related