Question: Getting the new error message now. Please help. Thank you. What changes would be needed to compile and render successfully? gear: 1 Access to fetch
Getting the new error message now. Please help. Thank you.
What changes would be needed to compile and render successfully?
gear:Access to fetch at My URL' from origin 'localhost:has been blocked by CORS policy: No 'AccessControlAllowOrigin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to nocors' to fetch the resource with CORS disabled.
My URLapigear:
Failed to load resource: net::ERRFAILED
My URLapigear:
Failed to load resource: the server responded with a status of
Here is the DataForm code:
import React, useState from 'react';
const DataForm addNewItem updateItem, deleteItem
const namesetNameuseState;
const brandsetBranduseState;
const pricesetPriceuseState;
const imagesetImageuseStatenull;
const errorsetErroruseStatenull;
const successsetSuccessuseStatefalse;
const handleImageChange e
setImageetarget.files;
;
const handleSubmit async e
epreventDefault;
if name.trimbrand.trimprice.trimimage
setErrorAll fields are required, including an image.;
setSuccessfalse;
return;
const formData new FormData;
formData.appendnamename;
formData.appendbrandbrand;
formData.appendpriceprice;
formData.appendimageimage;
try
const response await fetchMy URLapigear
method: 'POST',
body: formData,
;
const data await response.json;
if datasuccess
setSuccesstrue;
addNewItemdatanewItem;
setName;
setBrand;
setPrice;
setImagenull;
else
setErrordatamessage Failed to add the item.;
setSuccessfalse;
catch err
setErrorAn error occurred while submitting the form.;
setSuccessfalse;
;
return
Name
setNameetarget.value
Brand
setBrandetarget.value
Price
setPriceetarget.value
Image
error && error
success && Item added successfully!
Submit
;
;
export default DataForm;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
