2017-07-12 11 views
0

私は角度JSでzillow APIを使用してURLを取得しようとしています。AngularJS JSONP TypeError:url.replaceは関数ではありません

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(); 
 
    } 
 
]);

しかし、JSONPはエラーを返します。 JSONPパラメータとして使用されているURLでアクセスすると、Webブラウザが正しく表示されます。 このzillow APIはXMLデータを返します。 これをJSONタイプのデータとして取得するにはどうすればよいですか?

+0

のようにJSONに変換あなたの質問**のURLは** JSONPをサポートするリソースではありません – Phil

答えて

1

xml2jsonを使用できます。ここからそれを得る:

xml2json github

refrance追加:あなたは、APIからXML応答を取得した後、

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

とあなたのコントローラ内に、それはこの

var x2js = new X2JS(); 
    var jsonResponse= x2js.xml_str2json(your_xml); 
関連する問題