无法从angularjs中我自己的api获取JSONP数据

时间:2022-02-28 12:52:16

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

我试图从我自己的api获取数据但是无法成功获取相同的vegdata变量...这里是控制器代码

    $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

JSOn格式如下所示......我能够通过浏览器获取

[{"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"}]

1 个解决方案

#1


2  

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:

从回调查询字符串中检索yourCallBack。我不知道如何用python做这个,在asp.net mvc中我会这样:

string callback = Request.QueryString["callback"];

#1


2  

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:

从回调查询字符串中检索yourCallBack。我不知道如何用python做这个,在asp.net mvc中我会这样:

string callback = Request.QueryString["callback"];