1
myApp.config(['$httpProvider', function ($httpProvider) {
    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];
 }]);

$http.defaults.useXDomain = true;

$http.get('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=asp+site:codehint.ru').
    success(
        function (data, status, headers, config) {
            alert('answer');
        }
   );

Is not working! Because: Origin \site name\ is not allowed by Access-Control-Allow-Origin.

I have just started using AngularJS and forced to use $.getJSON because it is working fine in situation above. Can anybody show me the right solution of code above to make an AJAX call to outer services like Google?

1 Answer 1

4

You should try $http.jsonp instead.

You'll just have to add callback=JSON_CALLBACK to your request:

$http.jsonp('http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=asp+site:codehint.ru&callback=JSON_CALLBACK')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.