The problem occur when I am trying to send append data it accept in object form and I'm unable to get data from server it show request parameter invalid
function Traveller() {
const formData = new FormData();
formData.append('destination', myData?.data?.destination || '');
formData.append('source', myData?.data?.source || '');
formData.append('time', myData?.data?.time || '');
formData.append('type', myData?.data?.type || '');
formData.append('car_type', selectedCar?.name || '');
formData.append('distance', selectedCar?.distance || '');
formData.append('name', formValues?.name || '');
formData.append('email', formValues?.email || '');
formData.append('mobile_no', formValues?.mobile_no || '');
}
export const createBooking = async ( token, formData) => {
try {
const postData = {
api:'create-booking',
token: token,
formData:formData
};
const response = await axios.post(BASE_URL, postData, {
headers: {
"Content-Type": "multipart/form-data",
"Accept": "application/json",
}
});
console.log(response.data)
return (response);
} catch (error) {
console.log(error);
}
}
api
andtoken
to theformData
- since it isformData
you want to send in the requestFormData
but then put that into an object. You're supposed to doaxios.post(url, formData, config)
instead you hyaveaxios.post(url, someOtherObjectContainingFormData, config)
. It's not even quite clear what you want to do - either do the entirepostData
as aFormData
instance, or maybe you meant to useaxios(config)
.