我如何使用 angular js 在另一个 html 文件中使用从 json 响应中获取的数据
How can i use the data gotten from a json response in another html file using angular js
我有不同的 html 页面,在用户登录后,我有不同的数据被发回,我将不得不使用其中的一些数据和我的下一个 post url 在另一个 html 页面中。
例如,如果用户应该登录,如果用户已通过身份验证,我将获得用户 ID、性别和一些其他数据以在另一个页面中使用,因为我必须将所有内容连同它一起发送到另一个页面 activity.
在 JAVA
中执行类似 Bundle 或 SharedPreferences 的操作
这是我登录页面的代码
<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>
这是我在控制台日志中得到的结果{"RESULT":1,"MESSAGE":"SUCCESSFUL","EMPID":"2223444"}
我如何在另一个 html 页面(angularjs 控制器......另一个 html 文件)。以及如何在另一个 html 页面中使用相同的用户名..因为我要将用户名和 EMPID 一起发送..在我的另一个 html 页面
中
尝试使用 angular.js 构建单页应用程序。您可以使用 rootScope、工厂等轻松地在不同状态、控制器之间共享数据。
我有不同的 html 页面,在用户登录后,我有不同的数据被发回,我将不得不使用其中的一些数据和我的下一个 post url 在另一个 html 页面中。 例如,如果用户应该登录,如果用户已通过身份验证,我将获得用户 ID、性别和一些其他数据以在另一个页面中使用,因为我必须将所有内容连同它一起发送到另一个页面 activity.
在 JAVA
中执行类似 Bundle 或 SharedPreferences 的操作这是我登录页面的代码
<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>
这是我在控制台日志中得到的结果{"RESULT":1,"MESSAGE":"SUCCESSFUL","EMPID":"2223444"} 我如何在另一个 html 页面(angularjs 控制器......另一个 html 文件)。以及如何在另一个 html 页面中使用相同的用户名..因为我要将用户名和 EMPID 一起发送..在我的另一个 html 页面
中尝试使用 angular.js 构建单页应用程序。您可以使用 rootScope、工厂等轻松地在不同状态、控制器之间共享数据。