0

I am not getting any response from my AJAX call to the API. Few days back it was working fine and I was getting response JSON but now I am not able to get any JSON object. Mozilla does not give response JSON but shows no error but in Chrome I am getting net::ERR_INSECURE_RESPONSE

AngularJS code:

app.controller("LoginCtrl",
        function($scope, $http,$location,$rootScope) {
    $scope.login = function(user){
        $http({
            method: "POST",
            url: "https://aadvq11nwbv01.staples.com/wcs/resources/v1/member/login?storeId=10101&responseFormat=json",
            /*header: "Access-Control-Allow-Origin:*",*/
            header: "Content-Type: application/json",
            header: "Accept: application/json",
            data:{
                companyID: $scope.user.customerid,
                userID: $scope.user.userid,
                password: $scope.user.password
            }
        })
        .success(function (response){
            $rootScope.profile="xxx";
            userDetails = response;
            console.log(userDetails);
            $location.url("/profile")
        })
        .error(function (err){
            $scope.logerr="err";
            console.log(err);
        });
    }
});
  • Your url has "https" specified. Are you sure your backend has a valid SSL cert and can serve a https request? –  Aug 07 '15 at 17:01
  • I used the same url few days back and it was working fine.... – Pankaj Tripathi Aug 07 '15 at 17:02
  • Were any changes made to the backend server in the last few days? Did their https certificate expire? Can you access the url like a regular website in chrome and do you see any errors? –  Aug 07 '15 at 17:06
  • Sounds like a problem with your https certificates, I've had this happen to me with self-signed certificates where you have to navigate to the site clicking a button that says something like 'I'm aware of the risks, take me there' and then the cache is cleared while you remained on the site. Try clearing the cache again, closing the browser and opening it again. – yvesmancera Aug 07 '15 at 17:08
  • No nothing as such..I am able to access the API urls via Chrome – Pankaj Tripathi Aug 07 '15 at 17:09
  • Take a look at http://stackoverflow.com/questions/23688565/failed-to-load-resource-neterr-insecure-response it might help you. – yvesmancera Aug 07 '15 at 17:13
  • @PankajTripathi - Using Fiddler or Postman, can you check the server response to see if the response contains the "Access-Control-Allow-Origin: *" header? –  Aug 07 '15 at 17:15
  • yvesmancera I did the same but it sill doesn't work – Pankaj Tripathi Aug 07 '15 at 17:16
  • @user1 I am getting this response header via Swagger UI for APIs { "date": "Fri, 07 Aug 2015 17:17:32 GMT", "server": "IBM_HTTP_Server/7.0.0.27 (Unix)", "vary": "Accept-Encoding,User-Agent", "content-encoding": "gzip", "p3p": "policyref=\"http://qa11.staplesadvantage.com/w3c/p3p.xml\", CP=\"CAO DSP COR CURa ADMa DEVa OUR IND PHY ONL UNI COM NAV INT DEM PRE\"", "keep-alive": "timeout=4, max=1000", "connection": "Keep-Alive", "transfer-encoding": "chunked", "content-type": "application/json", "content-language": "en-US" } – Pankaj Tripathi Aug 07 '15 at 17:18
  • Based on that header listing, it looks like Access-Control-Allow-Origin isn't there. I can only guess it was there before, but I can indeed say that's your problem. – Katana314 Aug 07 '15 at 17:20
  • I added Access-Control-Allow-Origin when I was getting CORS related issues. But now even that isn't working – Pankaj Tripathi Aug 07 '15 at 17:23

2 Answers2

0

The reason could be you have specified in wrong way. header should be an object then define its properties in it.

Code

    $http({
        method: "POST",
        url: "https://aadvq11nwbv01.staples.com/wcs/resources/v1/member/login?storeId=10101&responseFormat=json",
        header: {
            "Content-Type: application/json",
            "Accept: application/json"
        },
        data:{
            companyID: $scope.user.customerid,
            userID: $scope.user.userid,
            password: $scope.user.password
        }
    })
Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299
0

The reason you get the error is that the SSL certificate provided by the webserver is not recognised and therefore not trusted. If you are using a self-signed certificate on your webserver this will explain it. Otherwise there is an issue with the setup of your certificate.

Jonas
  • 491
  • 6
  • 22