Access-Control-Allow-Origin error when getting Wordpress posts in Phonegap app

后端 未结 4 1399
南笙
南笙 2021-02-09 22:42

Hopefully someone can help me to resolve the following problem while developing a mobile app in phonegap. I am attempting to read posts from a wordpress installation but I get t

4条回答
  •  终归单人心
    2021-02-09 23:21

    So the problem that you are running into is commonly referred to as Cross Origin Security. Basically, most web-browsers will not allow you to pull in content from servers outside your own, unless the server says it is ok. To do this, the server needs to see an acceptable Access-Control-Allow-Origin in the headers.

    The good news is that this is fairly easy to fix, as Bowdenweb points out in How to Enable cors in WordPress.

    You only need to add the appropriate header to the headers.php file, like so

    
    
    

    Update 1

    As ILI pointed out, there is a plugin for Wordpress called WordPress-Cross-Domain-Plugin which resolved this issue for him.

提交回复
热议问题