我在我的页面上进行了简单的登录。登录后,我正在显示来自服务器的数据,这只是在刷新页面一次后显示。在我收到错误 500 之前:GET http://localhost:8080/getDesktop 500angular.js:14800 Possibly unhandled rejection: ...我的 AngularJS 代码如下:var app = angular.module("myApp", []);app.controller("myCtrl", function($scope, $http, $window, $timeout){//Username$scope.user = "";//Desktop$scope.storage = [];//Get username$http.get("/loggeduser", {transformResponse: function(response){ return JSON.stringify(response); }}).then(function(response) { $scope.user = response.data.substring(1, response.data.length-1);});//Show Desktop $http.get("/getDesktop").then(function(response){ for(var i = 0; i<response.data.length; i++){ $scope.storage[i] = {name: response.data[i]}; } return; });});后端://Returns Desktop@GetMapping("/getDesktop")public ArrayList<String> getDesktop() throws Exception { ArrayList<String> itemNames = new ArrayList<>(); if(kdxF.getUser() != null) { itemNames = kdxF.showDesktop(); // Just a function to return the Elements in an ArrayList if Strings // If user is logged in }else { throw new Exception("Not logged in!"); } return itemNames;}我收到消息“未登录”
1 回答

桃花长相依
TA贡献1860条经验 获得超8个赞
好的,我用一个丑陋的解决方案解决了它,但它有效。我不断检查用户是否为空,然后加载数据。
//Returns Desktop
@GetMapping("/getDesktop")
public ArrayList<String> getDesktop() throws Exception {
ArrayList<String> itemNames = new ArrayList<>();
int kill = 0;
while(kdxF.getUser() == null) { // FIXME
if(kill == 500) {
break;
}else {
Thread.sleep(5);
kill++;
}
}
itemNames = kdxF.showDesktop();
return itemNames;
}
如果你有更好的建议,请告诉我。:)
添加回答
举报
0/150
提交
取消