【发布时间】:2016-11-20 20:56:10
【问题描述】:
好的,我正在连接到一个新的桌面 API 以获取哪些票是开放的。现在我想使用 angular.js 在我自己的网络应用程序中动态显示它。目前我收到了来自 freshdesk API 的 json 响应,但我无法将其存储到变量中然后解析到我的角度控制器 $scope.tickets 变量中。
我该怎么做,有没有更好的方法?我对 Angular 和 jQuery 还很陌生,所以我愿意接受任何关于如何做到这一点的建议。
这是我的代码:
var jsonData;
function getData() {
$.support.cors = true;
var settings = {
"async" : true,
"crossDomain" : true,
"url" : "https://helpdesk.example.com/helpdesk/tickets.json",
"type" : "GET",
"headers" : { "authorization": basicAuth, "Content-Type" : "application/json"}
}
$.ajax(settings).done(function (response) {
//alert(response);
console.log(response);
jsonData = response;
});
}
我试过 jsonData = JSON.parse(response);但这不起作用,它是一个有效的 json 响应。
我的角度控制器:
app.controller('Ctrl', function ($scope, $http) {
$scope.tickets = jsonData;
});
【问题讨论】:
-
你不需要解析json
标签: jquery angularjs json ajax api