All the requests made by AJAX are being added a query string at the end and are being changed to HTTP instead of HTTPS without me specifying anything such in the code. If I remember correctly the ?_=1629050654857 query string is added by InfinityFree but why does it change the protocol?
HTTPS detection while using Cloudflare Flexible SSL is a bit tricky, using Full SSL is much easier that way.
If you’re using Full SSL (not strict), you can also get a Self Signed certificate from our SSL tool and use that. It’s about as secure, and you don’t need to renew it every three months.