The CORS Problems

Hello,
I used the blog. subdomain to build my own personal blog on the wordpress platform.At the same time, in the main website (main domain) written by html, I set up a page in it to display all the articles in WordPress.The access method is apjx, and the url is
blog.example.com/wp-json/wp/v2/posts?per_page=10&page=1&_fields=title,link,date;
However, I encountered a CORS error.The error message of the browser is
**blocked by CORS policy: No 'Access Control Allow Origin' header**
Both of the above websites are hosted on Infinityfree. I’ve used most of the .htacess or php methods on the Internet, but they don’t seem to work.
How can I get rid of this damn CORS error?
Thank you in advance.

Upgrade to premium hosting?
This is the limitation of free hosting

Unfortunately, CORS or embedding resources from domains hosted on our free hosting is not impossible. This also applies if they use the same base domain or are using the same account.

One workaround could be to migrate your website from a subdomain to a subdirectory. Suppose that right now, you have WordPress on blog.example.com and your HTML site on example.com. You could choose to migrate your WordPress site to example.com/blog/, and have your Javascript code point to that. Since they use the same domain (example.com), you don’t have this limitation.

6 Likes

OK,Thank you!

Okay, I already know,Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.