Reputation: 11
I am trying to fetch data from my own api but was not able to succeed in fetching the same to vegdata variable... here is the controller code
$scope.filterText = null;
$scope.vegdata =[];
$scope.init = function() {
url = "http://192.168.1.17\:5000/?callback=JSON_CALLBACK";
$http.jsonp(url).success(function(data){
console.log(data);
$scope.vegdata = data;
}).error(function(errord){
alert(errord);
});
JSOn format looks like below... the same I was able to fetch through browser
[{"name": "Tuar", "image": "0.0", "fat": "0.0", "alias": [{"vegname": "Tuar ", "language": "Hindi"}, {"vegname": "Red Gram", "language": "English"}, {"vegname": "Cajanus cajan", "language": "Botanical Name"}], "protein": "0.0", "energy": "0.0", "carbohydrates": "0.0"}]
Upvotes: 1
Views: 290
Reputation: 48982
Your response should be like this:
yourCallBack([{"name": "Tuar", "image": "0.0", "fat": "0.0", "alias": [{"vegname": "Tuar ", "language": "Hindi"}, {"vegname": "Red Gram", "language": "English"}, {"vegname": "Cajanus cajan", "language": "Botanical Name"}], "protein": "0.0", "energy": "0.0", "carbohydrates": "0.0"}]);
With yourCallBack
being retrieved from callback query string. I don't know how to do it with python, in asp.net mvc I would to something like this:
string callback = Request.QueryString["callback"];
Upvotes: 2