【发布时间】:2017-03-27 11:29:31
【问题描述】:
我正在创建一个 Angular 应用程序,该应用程序从在线可用的 api 获取一些数据,首先我从我的 php 脚本中获取 api 信息,而不是在我的 angularjs 应用程序中获取 json 结果,但给了我“SyntaxError: JSON中的意外标记t“,无法弄清楚原因。
我的 php:
header('Content-Type: application/json');
// jSON URL which should be requested
$json_url = "http://iatageo.com/getLatLng/OPO";
// Initializing curl
$ch = curl_init( $json_url );
// Configuring curl options
// Getting results
$result = curl_exec($ch); // Getting jSON result string
echo json_encode($result);
控制器:
$http.get('iata.php').then(function(response){
$scope.originLatLong = response.data;
console.log($scope.originLatLong);
});
【问题讨论】:
-
response是什么? -
304 未修改
-
您是否尝试解析响应?
-
试试 $scope.originLatLong = response;
-
当您尝试解析或编码 json 时会产生这种类型的错误。我怀疑编码时存在一些问题。
标签: javascript php angularjs json angularjs-scope