0

I am working with a web API for fetching some products. Here is my code.

$scope.loadApiProducts = function (ev) {
        $http({
            method: 'get',
            url: 'http://seller.digishoppers.com/webservice/productcategoryby/A123456/1/' + ev,
            //withCredentials: true,
        }).then(function success(res) {
            console.log('data is');
            console.log(res.data.data);
            $scope.productsApi = res.data.data;

        }, function error(res) {
            // console.log(res.data); 
        })
    }   

Can any one please help me to solve it . its working fine with chrome's cross extension

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • You need to :check the error (you defined an empty error callback) / check the network panel in your browser and gives the details (otherwise the syntax seems ok) – christophe.chapron May 22 '17 at 12:03
  • 3
    You are running through CORS issue, [not cross].. so ideally it should be handled at server side – anoop May 22 '17 at 12:04
  • What is your issue? – Mistalis May 22 '17 at 12:04
  • in Networ tab XMLHttpRequest cannot load http://seller.digishoppers.com/webservice/productcategoryby/A123456/1/1897. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. –  May 22 '17 at 12:10
  • @christophe.chapron –  May 22 '17 at 12:16
  • @anoop its already calling to an api wich is cors enabled . we just need to send a get request with headers if you know how to send it with angularjs please help –  May 22 '17 at 12:18
  • Copy/paste the error from the console – Peter Morris May 22 '17 at 12:23
  • HERE THE ERROR @pe –  May 22 '17 at 12:24
  • XMLHttpRequest cannot load http://seller.digishoppers.com/webservice/productcategoryby/A123456/1/1897. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. –  May 22 '17 at 12:24
  • try this. https://stackoverflow.com/a/29548043/3455035 – anoop May 22 '17 at 12:28
  • Request it note initiated after adding this @anoop –  May 22 '17 at 12:33
  • You have nothing to do at the angular side. Your server needs to accept localhost as origin ! little sample if you are working with asp net api : var cors = new EnableCorsAttribute(origins, "*", "*") { SupportsCredentials = true }; config.EnableCors(cors); – christophe.chapron May 22 '17 at 12:39
  • Actually I am working with laravel php and and this service is already cors enabled That's why After adding chrome's extension it gives me the fine result. @christophe.chapron –  May 22 '17 at 12:46
  • if service is CORS-enabled, you shouldn't even require chrome cors-extension., please cross check. – anoop May 22 '17 at 12:49

0 Answers0