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?

2
  • 1
    i found out this answer, it should be helpful Enable CORS on JSON API Wordpress Commented Dec 24, 2015 at 1: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. Commented Dec 25, 2015 at 3:42

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, thanks for your tip, but unfortunately it doesn't worked. It still showing the same error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.