When I did the following:
import { useGetPostQuery } from "./store/postApi";
export function App() {
const { data, isLoading, isFetching, isError, error } = useGetPostQuery(1);
if (isError)
return (
<div>
{error.status}
<br />
{error.data}
</div>
);
if (isLoading) return <div>loading...</div>;
return <div className={isFetching ? "posts--disabled" : ""}>{data}</div>;
}
I received an error:
PARSING_ERROR HELLO WORLD
Basically, I just want to return the string HELLO WORLD from the server. How should I avoid the parsing error?
A Code Sandbox for the example can be found here.
CodePudding user response:
I guess it expects a JSON response.
My PHP script:
echo json_encode(array("data"=>file_get_contents("data".$_GET["id"].".txt")));