2

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);
    }
}
2
  • You've shown two separate functions - how do they work with each other? why not append api and token to the formData - since it is formData you want to send in the request Commented Aug 14 at 8:20
  • You use FormData but then put that into an object. You're supposed to do axios.post(url, formData, config) instead you hyave axios.post(url, someOtherObjectContainingFormData, config). It's not even quite clear what you want to do - either do the entire postData as a FormData instance, or maybe you meant to use axios(config).
    – VLAZ
    Commented Aug 14 at 8:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.