1

in my page there is a button and i want to put some links depend on the user country.

i put this code in angular for example to understand my point.

this code not work for me.

did i missed something?

<html>

<head>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">

<script src="http://getbootstrap.com/assets/js/ie-emulation-modes-warning.js"></script>

<script>
var app = angular.module('gJson', []);
app.controller('gCtrl', function($scope, $http) {
  $http.get("//freegeoip.net/json/?callback=myGeoIP")
  .success(function myGeoIP(d) {
      if (d.country_code === 'US' || d.country_code === 'CA') {

         $scope.alertz = "This Offer Available in + d.country_code";
         $scope.uslink = 'http://example.US';

         }
        else
         {
         $scope.alertz = "This Offer Not Available in + d.country_code";
         $scope.uslink = "http://Example.net";
         }
  });
});

</script>

</head>


<body ng-app="gJson">

<div class="container" ng-controller="gCtrl">
    <div class="jumbotron">
        <p>{{alertz}}</p>
        <a class="btn btn-lg btn-success" ng-href="{{uslink}}" onclick="window.open(this.href, '_self', 'location=yes', 'toolbar=yes');">
        Enter
        </a>
    </div>
</div>

</body>

</html>
kingmaster
  • 25
  • 9

1 Answers1

2

change the url from //freegeoip.net/json/?callback=myGeoIP to //freegeoip.net/json/?callback

Now it return string like myGeoIp({"city":"","country_code":""...});

When you change the url the success result will be an object and you code will work

itssajan
  • 820
  • 8
  • 24