0

I am trying to get URL using zillow api in angular JS.

angular.module('account.settings').controller('AccountSettingsCtrl', ['$scope', '$http', '$sce',
  function($scope, $http, $sce) {

    var getZillowURL = function() {
      var url = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=X1-ZWz1ft20wfj30r_94p25&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA";
      var trustedUrl = $sce.trustAsResourceUrl(url);
      $http.jsonp(trustedUrl, {
          jsonpCallbackParam: 'callback'
        })
        .success(function(result) {
          $scope.mortgageLocation = result;
          console.log('success!');
          console.log(result);
        })
        .error(function(data, status) {
          console.log('error!');
          console.log(data);
        });
    };
    getZillowURL();
  }
]);

But JSONP returns error. When I access with the URL which is used as JSONP parameter, webbrowser shows correctly. This zillow API returns XML data. How can I get this as a JSON type data?

Pengyy
  • 37,383
  • 15
  • 83
  • 73
L. Daniel
  • 19
  • 1
  • 6

1 Answers1

1

You can use xml2json. get it from here :

xml2json github

Add a refrance :

<script src="xml2json.js"></script>

and in your controller, after you get the xml response from api convert it to json like this

  var x2js = new X2JS();
  var jsonResponse= x2js.xml_str2json(your_xml);
Emad Dehnavi
  • 3,262
  • 4
  • 19
  • 44