I'm currently facing an issue with a page I have set up to make requests to a php file through AJAX. The AJAX file returns a JSON response, but I'm encountering some problems.
The page is using UTF-8 charset for displaying special characters, while the default encoding of the AJAX file was ANSI. To ensure consistency and display correct symbols, I changed the encoding of the AJAX file to UTF-8. However, when using JSON.parse on the response, it throws an error "Uncaught SyntaxError: Unexpected token" if the AJAX file is encoded as UTF-8. Interestingly, changing back to ANSI encoding resolves this issue, although both outputs appear identical in xhr.responseText (without even using special characters in UTF-8).
Could it be that JSON.parse has trouble accepting responses from UTF-8 files? Or is there possibly a header setting required to address this issue? Your insights would be greatly appreciated. Thank you.