我有一个像这样的控制器:
ListNewsCtrl.$inject = ['$http', '$scope', 'datacontext'];
function ListNewsCtrl( $http, $scope, datacontext) {
$scope.realTimeData = [];
var url ="https://erikberg.com/mlb/standings.jsonformat=json&jsoncallback=?";
$http.jsonp(url)
.success(function (data) {
$scope.realTimeData = data;
console.log($scope.realTimeData)
});
};
当我跑的时候。我得到Uncaught SyntaxError:意外的令牌:错误。当我点击它时,我看到数据,数据被打印,但它表明我有一个Uncaught SyntaxError:
答案 0 :(得分:3)
您需要使用回调调用来包装json。这样的事情。
angular.callbacks._0 (
{
"standings_date": "2014-09-29T00:00:00-04:00",
"standing": [
{
"rank": 1,
"won": 90,
"lost": 72,
"streak": "W1",}]})
查看此plunker,我使用包装器的文件中使用完整的json:http://plnkr.co/edit/oX2UQRBA41FIHpwAP6AA?p=preview
这是一个web api控制器,可以满足您的需求。边缘有点粗糙,但它会让你更近。
using System;
using System.Web.Http;
using System.Web.Http.Cors;
using RestSharp;
namespace Atom.Authorization.Controllers
{
[RoutePrefix("api")]
[EnableCors("*", "*", "*")]
public class StandingsController : ApiController
{
// GET api/standings
[Route("standings/")]
[HttpGet]
public String Get()
{
RestClient client = new RestClient("https://erikberg.com/");
RestRequest request = null;
request = new RestRequest("mlb/standings.json", Method.GET);
request.RequestFormat = DataFormat.Json;
IRestResponse response = client.Execute(request);
return response.Content;
}
}
}