Data fetching not works just on mobile in next js 14 with error " TypeError: fetch failed
Unanswered
Amur catfish posted this in #help-forum
Amur catfishOP
const handleClick = async () => {
try {
const newResult = result.filter((item) => item?.subFeatures?.length > 0);
const body = {
type: params.id,
result: newResult,
total,
};
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/api/results`,
{
method: "POST",
body: JSON.stringify(body),
}
);
const data = await response.json();
if (response.ok) {
setContent(<Finishing currentPhase={currentPhase} />);
openModal();
setTimeout(() => {
closeModal();
router.push(`/results/${data.data._id}`);
}, 2000);
}
} catch (error) {
console.error(error);
}
};Data fetching not working only on mobile (working fine on pc) in next js 14 with this error
1 Reply
Toyger
you get your api url from env, but on mobile you open site at
192.168.1.101 so most likely in your env api_url you have either localhost or 127.0.0.1