1

I'm working with the WordPress JSON API plugin to make requests to get posts and etc from my blog.

When I try to access a simple url from browser it works perfectly, but when I try to access from my Ionic application this following erros occurs:

Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.

Do I need to do something from my WP blog to allow it?

Adam
  • 33
  • 8
  • 1
    i found out this answer, it should be helpful [Enable CORS on JSON API Wordpress](http://stackoverflow.com/questions/25702061/enable-cors-on-json-api-wordpress) – Stefano Saitta Dec 24 '15 at 01:20
  • Hey @StefanoSaitta thank you, but I checked and none of the stuff over there worked for me, I'm still getting the same error. – Adam Dec 25 '15 at 03:42

1 Answers1

0

It is most likely due to a cross-origin request. So try adding the below headers in your functions.php file.

function add_cors_http_header(){
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

}
add_action('init','add_cors_http_header');

Make sure that you haven't already used header in another file, or you will get a nasty error.

Hope it helps you.

Jenis Patel
  • 1,617
  • 1
  • 13
  • 20
  • Hello, thanks for your tip, but unfortunately it doesn't worked. It still showing the same error. – Adam Dec 25 '15 at 03:41