如何使用在另一个html文件中使用角js从json响应中获得的数据

时间:2021-11-02 03:28:38

I have different html pages, after a user logs in, i have different data been sent back, and i will have to use some of this data together with my next post to a url in another html page. for instance, if a user should log in, if the user is been authenticated, i will get the userid, sex, and some other data to be used in another page, since i have to send everything together with it on the other activity.

我有不同的html页面,在用户登录后,我有不同的数据被发送回来,我将不得不使用这些数据以及我的下一个帖子到另一个html页面的url。例如,如果用户应该登录,如果用户经过了身份验证,那么我将在另一个页面中使用userid、sex和其他一些数据,因为我必须在另一个活动中将所有内容连同它一起发送。

Doing something like Bundle or SharedPreferences in JAVA

在JAVA中执行捆绑或共享首选项之类的操作

This is the code for my login page

这是我登录页面的代码

       <script>
  var app = angular.module('myapp', [])
  app.controller('empcontroller', function($scope, $http){
  $scope.insertdata=function(){
    console.log("triggered");

$http({
    method: 'POST',
    url: "myurl",
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    transformRequest: function(obj) {
        var str = [];
        for(var p in obj)
        str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
        return str.join("&");
    },
    data: {username: $scope.fname, pswd: $scope.lname}
})
  .success(function(data, status, headers, config) {
        var mssg = data.MESSAGE;
        iqwerty.toast.Toast(mssg);
        console.log(data);      
        if ( data.RESULT === 1) {

          window.location.href = 'homes.html';
        } else {
          $scope.errorMsg = "Login not correct";
        }
      })
      .error(function(data, status, headers, config) {
        $scope.errorMsg = 'Unable to submit form';
      })

  }});</script>

This is the result i get in my console log{"RESULT":1,"MESSAGE":"SUCCESSFUL","EMPID":"2223444"} How can i use my data (that's the result i get as a response after my request has been sent to a given url) in another html page (angularjs controller..which is in another html file). and how can i use this same username in another html page..because, i am to send the username and the EMPID together..in my other html page

这是我在我的控制台日志{" result ":1,"MESSAGE":" success ","EMPID":"2223444"}中获得的结果我如何使用我的数据(这是我的请求被发送到一个给定的url后得到的结果)在另一个html页面(angularjs控制器)中。在另一个html文件中)。如何在另一个html页面中使用相同的用户名。因为,我要把用户名和EMPID一起发送。在我的另一个html页面

1 个解决方案

#1


2  

Try building a Single page application using angular.js. You can easily share data between different states, controllers using rootScope,factory etc.

尝试使用angular.js构建单个页面应用程序。您可以使用rootScope和factory等在不同状态之间轻松共享数据。

#1


2  

Try building a Single page application using angular.js. You can easily share data between different states, controllers using rootScope,factory etc.

尝试使用angular.js构建单个页面应用程序。您可以使用rootScope和factory等在不同状态之间轻松共享数据。