Website URL
http://pglifeproject.freepage.cc/
Error Message
When I click the Book Now button on my website, I get this error:
“Server returned an invalid response. Check Console.”
My JavaScript sends a POST request using fetch() to /api/book.php. The request returns HTTP 200 OK, but the response is HTML instead of JSON.
The HTML response contains /aes.js, sets a __test cookie, and redirects to /api/book.php?i=1.
My PHP endpoint uses json_encode() to return JSON. The website loads normally, and login, signup, and the Interested button work. Only Book Now is failing.
Could you please help me resolve this security verification issue for legitimate AJAX POST requests?
Other Information
Additional Information:
I checked the request in Chrome DevTools → Network → Fetch/XHR.
Request URL: http://pglifeproject.freepage.cc/api/book.php
Request Method: POST
Status Code: 200 OK
Response Content-Type: text/html
The response contains an HTML security challenge that loads /aes.js, sets a __test cookie, and redirects to /api/book.php?i=1 instead of returning JSON.
My booking.js uses fetch() with FormData to send the property_id. The PHP endpoint checks the login session, validates the property, checks for an existing booking, and inserts the booking into MySQL.
The Interested button works, but Book Now fails because the response cannot be parsed as JSON.
I would appreciate guidance on resolving this issue on InfinityFree hosting.