[Q] Parse jsonp results not working with $http


#1

I am making an app for android and i have a small issue.

I need pull a jsonp file via angular $http but, i’m just starting with ionic framework, please can anybody help me with my code.

	<ion-content
         start-y="55"
         padding="false"
         has-tabs="true"
         has-header="true"
         ng-controller="Buscar"
         >
   	<form ng-change="search()">
      <div id="search-box" class="bar bar-header item-input-inset">
        <div class="item-input-wrapper">
          <i class="icon ion-ios7-search placeholder-icon"></i>
          <input type="search" placeholder="Buscar por artista o canción..." ng-model="data.query">
          <i class="clear-search icon ion-ios7-close-empty" ng-click="clearSearch()"></i>
        </div>
      </div>
 	</form>
  <ul class="list">
    <li class="item item-thumbnail-left" ng-repeat="song in songs.Canciones Goear">
    	<img src="http://farm3.staticflickr.com/2944/15361367146_dfbb22f7f9_m.jpg">
    	<h2>{{ song.artista.text }}</h2>
    	<p>{{ song.titulo.text }}</p>
    </li>
  </ul>

</ion-content>

the code above is the content of my html file and this is my js code

 angular.module('tusmp3', ['ionic', 'tusmp3.controllers', 'tusmp3.services'])
 .controller('Buscar',function($scope){
  $scope.data = {};
    var doSearch = ionic.debounce(function(query) {
      var kimono = $http.get('https://www.kimonolabs.com/api/5ms9iici?apikey=cjN7aG4x1Z1M9M8YibCq1JBxFSfMl3sR');
      kimono.success(function(data, status, headers, config){
        if(data.lastrunstatus == 'success'){
          $scope.songs = data.results;
        }
      });
      kimono.error(function(data, status, headers, config){
        alert('No hay resultados. Comprueba tu conexión a internet!')
      })
    }, 500);

    $scope.search = function() {
      doSearch($scope.data.query);
      alert('No busca nada');
    }
});

Thanks for your valuable help…

:smile:


#2
var kimono = $http.jsonp('https://www.kimonolabs.com/api/5ms9iici?apikey=cjN7aG4x1Z1M9M8YibCq1JBxFSfMl3sR');
      kimono.success(function(data, status, headers, config){
        if(data.lastrunstatus == 'success'){
          $scope.songs = data.results;
        }
      });
      kimono.error(function(data, status, headers, config){
        alert('No hay resultados. Comprueba tu conexión a internet!')
      })

The .get method expects a json array (which is not parsed yet!), while the .jsonp requires a valid javascript method and gets executed, the json is already parsed that way