寶慕林4294392
2022-01-19 09:54:12
我在我的頁(yè)面上進(jìn)行了簡(jiǎn)單的登錄。登錄后,我正在顯示來(lái)自服務(wù)器的數(shù)據(jù),這只是在刷新頁(yè)面一次后顯示。在我收到錯(cuò)誤 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 回答

桃花長(zhǎng)相依
TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超8個(gè)贊
好的,我用一個(gè)丑陋的解決方案解決了它,但它有效。我不斷檢查用戶是否為空,然后加載數(shù)據(jù)。
//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;
}
如果你有更好的建議,請(qǐng)告訴我。:)
添加回答
舉報(bào)
0/150
提交
取消