Angular6 在不同浏览器上为相同的api调用获取不同的响应

Angular6 在不同浏览器上为相同的api调用获取不同的响应,angular6,internet-explorer-11,angular-services,Angular6,Internet Explorer 11,Angular Services,我正在用Angular6做一个项目。三天来我一直在为一个奇怪的问题挠头。 问题是,对于传递了正确参数的相同api调用,我在两个浏览器(chrome和InternetExplorer11)上得到了不同的响应。chrome的响应非常好,并且更新了 算法: 我有两种方法 populateProjectTimesheetUsers():它将时间表的用户从服务器中带出 onSaveAddUserInstructionClick():它将新用户保存到时间表中 流程: 使用“onSaveAddUserInst

我正在用Angular6做一个项目。三天来我一直在为一个奇怪的问题挠头。 问题是,对于传递了正确参数的相同api调用,我在两个浏览器(chrome和InternetExplorer11)上得到了不同的响应。chrome的响应非常好,并且更新了

算法: 我有两种方法

  • populateProjectTimesheetUsers():它将时间表的用户从服务器中带出
  • onSaveAddUserInstructionClick():它将新用户保存到时间表中
  • 流程: 使用“onSaveAddUserInstructionClick()”将用户保存到时间表后,将调用“populateProjectTimesheetUsers()”以获取屏幕上更新的用户数据

    问题: 在chrome上,“populateProjectTimesheetUsers()”正在获取更新的数据,但在IE上,它会带来旧数据,即IE上的最新用户列表中没有最新的用户

    代码:

    onSaveAddUserInstructionClick(){
        this.addUserModel.WorkerId = this.addUserModel.Worker.Key;
        this.adminTimeEntryService.addUserToInstruction(this.selectedProjectId, this.addUserModel.WorkerId).subscribe(
          (response) => {
            this.messageService.showMessage("success","User added to instruction successfully");
            this.populateProjectTimesheetUsers(this.selectedProjectId);
            this.addUserModalRef.hide();
          },
          (error) => {
            this.handleError(error);
            this.addUserModalRef.hide();
          }
        )
      }
    
    populateProjectTimesheetUsers(projectId = null) {
        if (projectId != null) {
          this.userGridRowData = [];
    
          this.adminTimeEntryService.getTimesheetUsersByProjectId(projectId).subscribe(
            (response) => {
              this.serviceLineGridRowData = response.ServiceLines;
              this.userGridRowData = response.Users;
              console.log("this.userGridRowData1: " , this.userGridRowData);
              console.log("response1: " , response );
              for(let i=0; i< this.userGridRowData.length; i++){
                this.userGridRowData[i].AddInstructionRate = "Add Instruction Rate"; 
                this.userGridRowData[i].RemoveUserFromInstruction = "Remove User From Instruction";
              }
    
              console.log("this.this.userGridRowData2: " , this.userGridRowData);
              console.log("response2: " , response );
    
              setTimeout(()=>{
                console.log("this.this.userGridRowData3: " , this.userGridRowData);
                console.log("response3: " , response );
                this.userGridApi.setRowData(this.userGridRowData);
                this.serviceLineGridApi.setRowData(this.serviceLineGridRowData);
              }, 0);
            },
            (error) => {
              Logger.logError(`getTimesheetUsersByProjectId error: ${JSON.stringify(error.error)}`);
            }
          );
        }
      }
    
    onSaveAddUserInstructionClick(){
    this.addUserModel.WorkerId=this.addUserModel.Worker.Key;
    this.adminTimeEntryService.addUserToInstruction(this.selectedProjectId,this.addUserModel.WorkerId)。订阅(
    (回应)=>{
    this.messageService.showMessage(“成功”,“用户已成功添加到指令”);
    this.populateProjectTimesheetUsers(this.selectedProjectId);
    this.addUserModalRef.hide();
    },
    (错误)=>{
    此.handleError(错误);
    this.addUserModalRef.hide();
    }
    )
    }
    populateProjectTimesheetUsers(projectId=null){
    if(projectId!=null){
    this.userGridRowData=[];
    this.adminTimeEntryService.getTimesheetUsersByProjectId(projectId).subscribe(
    (回应)=>{
    this.serviceLineGridRowData=response.ServiceLines;
    this.userGridRowData=response.Users;
    log(“this.userGridRowData1:”,this.userGridRowData);
    日志(“response1:”,response);
    for(设i=0;i{
    log(“this.this.userGridRowData3:”,this.userGridRowData);
    日志(“response3:”,response);
    this.userGridApi.setRowData(this.userGridRowData);
    this.serviceLineGridApi.setRowData(this.serviceLineGridRowData);
    }, 0);
    },
    (错误)=>{
    Logger.logError(`getTimesheetUsersByProjectId错误:${JSON.stringify(error.error)}`);
    }
    );
    }
    }
    
    尝试:

    onSaveAddUserInstructionClick(){
        this.addUserModel.WorkerId = this.addUserModel.Worker.Key;
        this.adminTimeEntryService.addUserToInstruction(this.selectedProjectId, this.addUserModel.WorkerId).subscribe(
          (response) => {
            this.messageService.showMessage("success","User added to instruction successfully");
            this.populateProjectTimesheetUsers(this.selectedProjectId);
            this.addUserModalRef.hide();
          },
          (error) => {
            this.handleError(error);
            this.addUserModalRef.hide();
          }
        )
      }
    
    populateProjectTimesheetUsers(projectId = null) {
        if (projectId != null) {
          this.userGridRowData = [];
    
          this.adminTimeEntryService.getTimesheetUsersByProjectId(projectId).subscribe(
            (response) => {
              this.serviceLineGridRowData = response.ServiceLines;
              this.userGridRowData = response.Users;
              console.log("this.userGridRowData1: " , this.userGridRowData);
              console.log("response1: " , response );
              for(let i=0; i< this.userGridRowData.length; i++){
                this.userGridRowData[i].AddInstructionRate = "Add Instruction Rate"; 
                this.userGridRowData[i].RemoveUserFromInstruction = "Remove User From Instruction";
              }
    
              console.log("this.this.userGridRowData2: " , this.userGridRowData);
              console.log("response2: " , response );
    
              setTimeout(()=>{
                console.log("this.this.userGridRowData3: " , this.userGridRowData);
                console.log("response3: " , response );
                this.userGridApi.setRowData(this.userGridRowData);
                this.serviceLineGridApi.setRowData(this.serviceLineGridRowData);
              }, 0);
            },
            (error) => {
              Logger.logError(`getTimesheetUsersByProjectId error: ${JSON.stringify(error.error)}`);
            }
          );
        }
      }
    
  • 我通过将变量赋值给一个来检查引用 另一个

  • 我检查了函数调用的a同步性

  • 刷新缓存

  • 但问题仍然存在。如果有人指出这个问题,这样我们就可以了解。
    可能是我遗漏了最微小的东西,但我无法找到它。

    也许问题与IE浏览器缓存有关

    尝试清除IE浏览器历史记录,并参考和添加http标头,然后禁用缓存:

    headers = new Headers({
            'Cache-Control':  'no-cache, no-store, must-revalidate, post- 
                                check=0, pre-check=0',
            'Pragma': 'no-cache',
            'Expires': '0'
        });
    

    问题可能与IE浏览器缓存有关

    尝试清除IE浏览器历史记录,并参考和添加http标头,然后禁用缓存:

    headers = new Headers({
            'Cache-Control':  'no-cache, no-store, must-revalidate, post- 
                                check=0, pre-check=0',
            'Pragma': 'no-cache',
            'Expires': '0'
        });
    

    我错过了浏览internet explorer网络统计数据的机会。它强制api调用从缓存中获取数据

    我强制我的api调用从真正的服务器获取数据并绕过缓存。 我用以下方式设置标题

    headers = headers.set('Cache-control','no-cache');
    headers = headers.set('Pragma','no-cache');
    

    我错过了浏览internet explorer网络统计数据的机会。它强制api调用从缓存中获取数据

    我强制我的api调用从真正的服务器获取数据并绕过缓存。 我用以下方式设置标题

    headers = headers.set('Cache-control','no-cache');
    headers = headers.set('Pragma','no-cache');