为了账号安全,请及时绑定邮箱和手机立即绑定

登录后/刚刚刷新页面后未加载数据

登录后/刚刚刷新页面后未加载数据

宝慕林4294392 2022-01-19 09:54:12
我在我的页面上进行了简单的登录。登录后,我正在显示来自服务器的数据,这只是在刷新页面一次后显示。在我收到错误 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;

}

如果你有更好的建议,请告诉我。:)


查看完整回答
反对 回复 2022-01-19
  • 1 回答
  • 0 关注
  • 196 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号