Reputation: 67
I can't use angular $http service for my services. I have to use YQL for JSON conversion. Isn't $http like jquery $.ajax? Here is my code:
function cfgFunction($routeProvider)
{
$routeProvider.
when("/",{templateUrl:"partials/table.html"})
}
function testctrl($scope, $http) {
var s = 'http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%20%3D%20%22http%3A%2F%2Fapp.mytrading.it%3A8080%2FTS%2Fvis_dati.AllQuotes%3Fp_profilo%3D%26p_indice%3D%26p_id_cliente%3D%26p_nazione%3D%26p_num%3D%26p_titolo%3D%22&format=json&callback=';
$http.get(s).success(function(data) {
$scope.titoli = data.query.results.ROWSET.ROW;
}).
error(function(data, status, headers, config) {
alert("error!")
});
}
angular.module('MytApp',[]).config(cfgFunction);
Upvotes: 3
Views: 2037
Reputation: 35829
In my opinion you should use jsonp:
$http.jsonp(url).success(...);
Also dont forget to add callback=JSON_CALLBACK to your query.
I have a working example using YQL on my jsFiddle.
Since http is asynchronuous, you have two options to process it:
Both are shown in the example.
Upvotes: 6
Reputation: 3118
Try $http.jsonp(url,config) since you're sending request to a remote domain.
Upvotes: 0