Jquery ajax access control allow origin4/13/2024 ![]() ![]() Also you should run that all through btoa() - because you’re rolling your own header.ĬORS - yes you will need some headers here. Here it’s the http basic username really and there is no password. ‘Authorization’: ‘Basic MY_API_KEY’ - don’t forget that you need to add a ‘:’ to the end of your API key. I think it would be worth reading these old queries… Don’t forget that even though you’re using jQuery, it doesn’t do everything for you. Well technology moves fast but I’m sure these will still help you. I have searched the forum for related questions and only found that issues had been found and fixed in 2017. ![]() I have read the Companies House API docs over and over and am failing to see what I am missing. What I’d like: I call the GET, receive a 200 response from the GET request, with the data I expect with no javascript errors. Why is there an OPTIONS request prior to the expected GET request? However, my AJAX call always fails (with the Javascript error shown above) and falls into the error block, so I am never in a position to see the successful response from the GET. I believe the GET is made as a result of a redirect from the OPTIONS request. The second is a GET and returns a 200 with the expected response containing the data I am after - The initiator is marked as “Other”. Interestingly, when looking at the Network tab of DevTools, I can see 2 entries under “XHR” as a result of my single AJAX call.īoth have the same request URL as my AJAX code above, but the first has a method of OPTIONS, which returns a 204 and I can see the initator is my AJAX call. 77 - Windows 10 Pro), I get the following error in my DevTools console: Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.īefore attempting to write any Javascript, I proved out that I could call this API using POSTMAN, and was able to get a successful response and had data coming back. When calling this using Google Chrome (Version. I am attempting to call the GET /search/companies API using the JQuery Ajax capability, to perform a company name search. Note: I have searched the forum for related questions and only found that issues had been found and fixed in 2017.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |