Form verilerini göndermeye ve API'DE bir post isteği yapmaya ve tahminler almaya çalışıyorum ancak hatayı alıyorum SyntaxError: Unexpected token < in JSON at position 0
yaparken. API'yi kontrol ettim ve gayet iyi. Aşağıdaki gönderi isteğini ekledim. Formlarla ilgili bir sorun olduğunu tahmin ediyordum. yanılıyorsam lütfen beni düzeltin.
const FirstProject = () => {
const [solutestate, setSoluteState] = useState("");
const [solventstate, setSolventState] = useState("");
const [fetchData, setFetchData] = useState("");
const [Error, setError] = useState(null);
const { register, handleSubmit, control } = useForm({
defaultValues: {
solute: "",
solvent: "",
},
});
const formData = new FormData();
const onSubmit = (data) => {
formData.set("solute", data.solute);
formData.set("solvent", data.solvent);
fetch("https://flask-api-test1.herokuapp.com/predict", {
method: "post",
body: formData,
})
.then((res) => res.json())
.then((result) => {
setFetchData(result.result.predictions);
//console.log(result.result.predictions);
//console.log(Object.entries(result));
// setIsPending(false);
})
.catch((err) => {
console.log(data);
setError(err.error);
console.log(err);
});
};
<form onSubmit={handleSubmit(onSubmit)}>
<input
{...register("solute")}
placeholder="First Name"
onChange={(e) => setSoluteState(e.target.value)}
value={solutestate}
/>
<input
{...register("solvent")}
placeholder="First Name"
onChange={(e) => setSolventState(e.target.value)}
value={solventstate}
/>
<input type="submit" />
</form>