I am using AngularJS, but I've encountered the same issue with JQuery and in plain JavaScript as well. If the remote server I am accessing sets Access-Control-Allow-Origin then either the success
or error
methods is invoked.
When there is no Access-Control-Allow-Origin neither of those is called and I can only see the error in the console. Is there a way to capture the
No Access-Control-Allow-Origin
error in my JavaScript code?
And just in case you are interested in a use-case, I am building a front-end for PyPi https://pypi.python.org/ There, you can get the information about packages in JSON format. (e.g. https://pypi.python.org/pypi/dspy/json ). Those requests set the Access-Control-Allow-Origin, but if I send a request for a package that is not on the server (e.g. https://pypi.python.org/pypi/dspyz/json ) then I get No Access-Control-Allow-Origin and thus I don't get anything invoked in my JavaScript code.
Update
After some more experiments I found out that the error
method was called it just threw an exception due to some issue with the code I used and that mislead me.