I have a page on my website with a stream list, and I’m having a problem with my client ID.
I’m really new to the jQuery/javascript so I just know the basics. I created an Client ID and added the header to my jquery function, but im getting this error:
“Request header field Client-ID is not allowed by Access-Control-Allow-Headers in preflight response.”
You’re getting the error because ajaxSetup applies to every AJAX call once you’ve turned it on. With an AJAX request, the browser sends a preflight OPTIONS call to the server. In this case, the server is saying that it doesn’t allow the Client-ID header for the OPTIONS call.
Is there a particular reason you are calling ajaxSetup and setting all of those particular headers? It’s generally not needed. Also, there is a copy and pasteable jQuery example in the original Client-ID blog post.
getJSON doesn’t allow you to set headers on a request, which is why I suggested the code in the blog post.
You need to replace jQuery.getJSON with the jQuery.ajax call. You’re calling both right now, and you’re seeing the 400 due to jQuery.getJSON failing. You new code would look like this:
Why are you setting the Access-Control-Allow-* headers in your ajaxSetup? They’re headers for a server to return, not for a client to send, and it’s likely the cause of your error.