0

How to solve cross-domain-issue I do call json like this, but here I am getting cross domain error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://.........json. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

my code

app.factory('appServices', function($http){
    var servicesData = {};
      servicesData.homeSearch = function(){
        return $http({
            method: 'GET',
            url   : 'http://sg.media-imdb.com/suggests/t/tita.json'
        }).success(function(data, status , header, config){
            console.log('Success')
        })
        .error(function(data, status , header, config){
              console.log('error') 
        });
    }
    return servicesData;
});

Full code here http://codepen.io/shibinragh/pen/obxGmQ

Sorry I am a beginner in development, I don't know much about cross-domain issue

ShibinRagh
  • 6,530
  • 4
  • 35
  • 57
  • `How to solve cross-domain-issue` - the server needs to either emit CORS headers, or have a `jsonp` alternative ... fortunately for you, that URL responds with jsonp, not json, despite returning `Content-Type: application/json` – Jaromanda X Dec 18 '15 at 11:29
  • 1
    This means that the server is not allowing requests come from a different domain. You can try and get around this by using `jsonp` or else the server side code needs to be changed to allow CORS – Paul Fitzgerald Dec 18 '15 at 11:30
  • Understood can you help me with codepen :) – ShibinRagh Dec 18 '15 at 11:33
  • check this out http://stackoverflow.com/questions/12066002/parsing-jsonp-http-jsonp-response-in-angular-js – Paul Fitzgerald Dec 18 '15 at 11:34
  • http://codepen.io/anon/pen/LGNOxo try that code. let me know if it works for you – Paul Fitzgerald Dec 18 '15 at 11:35
  • improved but not success – ShibinRagh Dec 18 '15 at 11:48
  • headers : {'Content-Type': 'application/x-www-form-urlencoded'} –  Dec 18 '15 at 12:33
  • and also may i know which api service you are using i mean php,.net or java ? –  Dec 18 '15 at 12:33
  • I dont know which api , I got it from online and I am doing it learning purpose eg: http://sg.media-imdb.com/suggests/t/tita.json - help me with codepen – ShibinRagh Dec 18 '15 at 12:50

0 Answers0