lundi 29 décembre 2014

$http Cross Origin Request Blocked by Angular JS


I am trying to implement search suggestion using one of our Suggestions API "https://SuggestionsAPI.net/suggest?key=xyz" which is working fine with Ajax GET request but when I am trying to use it with Angular $http service, it is throwing me error is console:



Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote
resource at https://SuggestionsAPI.net/suggest?key=xyz. This can be fixed by moving the
resource to the same domain or enabling CORS.


Further I tried :



$httpProvider.defaults.headers.get = { 'Access-Control-Allow-Origin': '*' };
$httpProvider.defaults.headers.get = { 'Access-Control-Request-Headers': 'X-Requested-With, accept, content-type' };
$httpProvider.defaults.headers.get = { 'Access-Control-Allow-Methods': 'GET, POST' };
$httpProvider.defaults.headers.get = { 'dataType': 'jsonp' };


I am stuck here thinking why same GET request is blocked by browser when using Angular JS. Please suggest me to eliminate it.





Aucun commentaire:

Enregistrer un commentaire