Cannot query API from Javascript (problem with Access-Control-Allow-Origin)
I'm having problem with sending AJAX requests to your JSON API from inside javascript. Here is the error:
XMLHttpRequest cannot load http://ws.detectlanguage.com/0.2/detect?q=buenos+dias+se%C3%B1or&key=demo. Origin http://localhost:9292 is not allowed by Access-Control-Allow-Origin.
Pls help
3
votes
Stefan Nguyen
shared this idea
Yes, direct access from the browser using javascript is denied because it would disclose your API key. To solve this problem we suggest creating “proxy” script on your server. Javascript would send data to the script and the script would forward request to the API.
-
Stefan Nguyen commented
Great! Thank you :)