Can not fetch data,and the error what I have seen is first time
I am testing it on laptop ,so I am using window.location.origin to fetch data
let jsonObject = await JSON.stringify({
name,
description,
cetegory,
thumb,
images,
selling_price_canada: sellingStyle === 'per_price' ?selling_price_canada : 'none',
selling_price_india: sellingStyle === 'per_price' ?selling_price_india : 'none',
selling_Amount: sellingStyle === 'per_price' ? selling_Amount : 'none',
selling_style,
selling_country,
size_and_price,
delivery_charge_in_canada,
delivery_charge_in_india
})
let fetchOptions = {
method:'POST',
headers: {
'Content-Type': 'application/json'
},
body: jsonObject
}
uploadTheProductBtn.style.opacity = .7;
uploadingStatus = true;
let url = window.location.origin + '/api/api_s/upload-product';
fetch(url, jsonObject)
.then(res => res.json())
.then(({error, success}) => {
if (error) return alert(error)
if (success) return alert('success');
})
.catch(e => console.log(e))
.finally(e => {
uploadTheProductBtn.style.opacity = 1;
uploadingStatus = false;
})
And I found This error –
TypeError: Failed to execute ‘fetch’ on ‘Window’: The provided value is not of type ‘RequestInit’
I was expecting to post data on the server