0
无法输入success()函数,而是在位于JSON.parse()位置0的JSON中出现'Unexpected token R'语法错误。 但是所有的后台数据库操作都是按照他们应该进行的。SyntaxError:JSON中位置0处JSON.parse处的意外标记R(<anonymous>)
注:我不是从AJAX调用
<html ng-app="PlaylistApp">
<head>
<meta charset="utf-8">
<title>Angular.js Example</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="lib/angular.min.js"></script>
<script>
var playlistApp = angular.module('PlaylistApp', []);
playlistApp.controller('PlaylistCtrl', function ($scope, $http)
{
$http({
method : 'GET',
url : 'http://localhost:8080/SignageSoC/api/playlist/all'
}).then(function success(response) {
$scope.playlists = response.data;
});
$scope.removePlaylist = function(index, playlistId)
{
var i = index;
alert(i);
alert(playlistId);
$http({
method : 'DELETE',
url : 'http://localhost:8080/SignageSoC/api/playlist/'+ playlistId
}).then(function success() {
alert(i);
$scope.playlists.splice(i, 1);
});
}
});
</script>
</head>
<body ng-controller="PlaylistCtrl">
<div>
<br>
<br>
<br>
<table class="center">
<tr>
<th>PlaylistId</th>
<th>Name</th>
<th>Total_duration</th>
<th>Play_continuous</th>
<th>Start_time</th>
<th>End_time</th>
<th>Update</th>
<th>Remove</th>
</tr>
<tr data-ng-repeat="(index,x) in playlists">
<td>{{x.playlistId}}</td>
<td>{{x.name}}</td>
<td>{{x.total_duration}}</td>
<td>{{x.play_continuous}}</td>
<td>{{x.start_time}}</td>
<td>{{x.end_time}}</td>
<td><button data-ng-click="updatePlaylist(index)">Update</button></td>
<td><button data-ng-click="removePlaylist(index, x.playlistId)">Delete</button></td>
</tr>
</table>
</div>
</body>
</html>
“但我不打算解析代码中的任何东西” - 请[阅读文档](https://docs.angularjs.org/api/ng/service/$http):** Default Transformations ...响应转换...如果检测到JSON响应,请使用JSON解析器对其进行反序列化。** – Quentin
@Quentin,我看了一下文档,但在这里我只是返回一个字符串,表示特定的字符已被删除。而且我并没有试图对此做出任何反应,我只是想在成功时进行拼接操作。 –
而Angular认为你用JSON响应并抛出一个错误,因为它不是有效的JSON。 – Quentin