-2

angular.module('BeautyCare', ['ionic'])
 
 .config(function($stateProvider, $urlRouterProvider) {

  $stateProvider
    .state('tabs', {
      url: "/tab",
      abstract: true,
      templateUrl: "templates/tabs.html"
    })
    .state('tabs.Store', {
      url: "/Store",
      views: {
        'Store-tab': {
          templateUrl: "templates/Store.html",
          controller: 'StoreTabCtrl'
        }
      }
    })
    
    .state('tabs.SalonGalary', {
      url: "/SalonGalary",
      views: {
        'SalonGalary-tab': {
          templateUrl: "templates/SalonGalary.html",
          controller :'SalonGalaryCtrl'
        }
      }
    })
    
    .state('tabs.Profile', {
      url: "/Profile",
      views: {
        'Profile-tab': {
          templateUrl: "templates/Profile.html"
        }
      }
    })

    .state('tabs.Alerts', {
      url: "/Alerts",
      views: {
        'Alerts-tab': {
          templateUrl: "templates/Alerts.html"
        }
      }
      });

   $urlRouterProvider.otherwise("/tab/Store");

});


.controller('StoreTabCtrl', function($scope,$http,$log) {
    var items =null;
    $log.debug('start debug');
    var url="http://open.api.ebay.com/shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&ResponseEncodingType=JSON";
    url+="&appid=API_ID&callback=JSON_CALLBACK._0";
    url+="&callname=FindPopularItems&version=713?callback=JSON_CALLBACK";
   $log.debug($http.jsonp(url)
            .success(function(data) {
            items=data;
            console.log(items);
            })
            .error(function(data) {
                //alert("ERROR");
            }));        
});
  <html >
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
    
    <title>Beauty Care</title>
    <!-- MyBeauty , BeautyCare,BeautyEye,BeautyShop,BeautySalon !-->

    <link href="lib/ionic/css/ionic.css" rel="stylesheet">
    <script src="lib/ionic/js/ionic.bundle.js"></script>
    <script src="js/app.js"></script>
    <script src="js/Service.js"></script>
    <script src="js/Controllers.js"></script>
   <!--  <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBLSOMXsw_sxOlRpyBj16g5iaewLHDpSes&libraries=places"></script>
 -->
  </head>

  <body ng-app="BeautyCare">
    
    <ion-nav-bar class="bar-positive">
      <ion-nav-back-button>
      </ion-nav-back-button>
    </ion-nav-bar>
             
    <ion-nav-view></ion-nav-view>


    <script id="templates/tabs.html" type="text/ng-template">
      <ion-tabs class="tabs-icon-top tabs-positive">

        <ion-tab title="" icon="ion-ios-cart" href="#/tab/Store">
          <ion-nav-view name="Store-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="" icon="ion-navicon-round"  href="#/tab/SalonGalary">
          <ion-nav-view name="SalonGalary-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="" icon="ion-android-person" ui-sref="tabs.Profile">
          <ion-nav-view name="Profile-tab"></ion-nav-view>
        </ion-tab>

        <ion-tab title="" icon="ion-ios-bell" ui-sref="tabs.Alerts">
          <ion-nav-view name="Alerts-tab"></ion-nav-view>
        </ion-tab>
      </ion-tabs>
    </script>

    <script id="templates/Store.html" type="text/ng-template">
      <ion-view view-title="BeautyCare Store" cache-view="false">
        <ion-content class="padding" >
        <ion-list>
      <ion-item class="item-icon-right" ng-repeat="item in items">
          <h1>{{item.TimeStamp }}</h1>
          <!--<p>{{ item.title}}</p> !-->
          <i class="icon ion-chevron-left icon-accessory"></i>
          <ion-option-button class="button-positive" ng-click="viewFriend(viewFriend(data.idfriends))">View Friend</ion-option-button>
          <ion-option-button class="button-assertive" ng-click="deleteFriend(remove(data.idfriends))">Delete</ion-option-button>
      </ion-item>
    </ion-list>
        </ion-content>
      </ion-view>
    </script>

    
    
    <script id="templates/SalonGalary.html" type="text/ng-template">
      <ion-view view-title="BeautyCare Salon Galary" cache-view="false">
        <ion-content class="padding">
         
        </ion-content>
      </ion-view>
    </script>

    
    <script id="templates/Profile.html" type="text/ng-template">
      <ion-view title="My Profile" cache-view="false">
        <ion-content>
         
        </ion-content>
      </ion-view>
    </script>

     <script id="templates/Alerts.html" type="text/ng-template">
      <ion-view view-title="My Alerts" cache-view="false">
        <ion-content class="padding">
          
        </ion-content>
      </ion-view>
    </script>


  </body>
</html>
  
    

</body>
</html>

I tried to use $http.get with no luck , the code showing unexpected error. i appreciate any help to solve this issue or workaround to use $http.get . I tried different examples but still not getting issues solved. Thanks in advance

  • Nobody will help you out with your issue if you only post images of your code and error, and especially not if both images don't even show the full details. Copy the text of your code into your question, along with the full text of the error message. – Luke Woodward Dec 03 '16 at 20:47
  • Thank you Luke , i will edit and post the code – Mohammed al-kahtani Dec 03 '16 at 21:01
  • 1
    I asked you to include the text of the error message in the question as well. Please edit your question to include that. – Luke Woodward Dec 03 '16 at 22:22
  • if you just run the code snippet you well see the error message , the error message as below : shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&ResponseEncodingType=JSON&appid=Mawsem77f-2832-4be9…:1 Uncaught SyntaxError: Unexpected token : – Mohammed al-kahtani Dec 04 '16 at 11:01

1 Answers1

0

Let's take a closer look at the URL you are attempting to send to the eBay API:

http://open.api.ebay.com/shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&
  ResponseEncodingType=JSON&appid=Mawsem77f-2832-4be9-93d8-e257a245be3&
  callback=JSON_CALLBACK._0&callname=FindPopularItems&version=713?callback=JSON_CALLBACK

I counted three problems with this:

  • the version parameter has an invalid value: 713?callback=JSON_CALLBACK. This parameter appears to require a numeric value. Note that this part of the URL is already in the query string, so the ? here won't be interpreted as the start of the query string or as an argument separator.

  • If callback=JSON_CALLBACK at the end of the URL is supposed to be another URL parameter name and value, then you have specified the callback parameter with two different values. You only need to specify this parameter once, and you also need to make up your mind about which value to use.

  • As you are making a JSONP request you need to specify the name of a function to wrap the returned JSON in. However, according to the eBay API documentation, you are using the wrong parameter for the name of the callback function. If the parameter callback has the value true, the response will be wrapped in a call to a function named _cb_FindPopularItems. Other values for this parameter appear to be ignored. It seems you want to use the callbackname parameter instead. So, try removing both callback parameters from your URL and adding either callbackname=JSON_CALLBACK or callbackname=JSON_CALLBACK._0 (it's not clear which one you intend here).

    This also explains the syntax error: responses to JSONP requests are assumed to be executable JavaScript but the response you are getting is actually some JSON data.

I have not tested this, but I would hope the following URL (wrapped for readability) would work. You may need to add the ._0 suffix to the callback name:

http://open.api.ebay.com/shopping?GLOBAL-ID=EBAY-IN&QueryKeywords=Iphone&
  ResponseEncodingType=JSON&appid=Mawsem77f-2832-4be9-93d8-e257a245be3&
  callbackname=JSON_CALLBACK&callname=FindPopularItems&version=713

Finally, please consider changing your eBay app ID. You've now posted it on the public internet and anyone who views this question can now use it. I've never used eBay nor its API before, so I'll leave it up to you to figure out how to do this.

Community
  • 1
  • 1
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104