2

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.

Doing something like Bundle or SharedPreferences in 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

Israel Meshileya
  • 293
  • 4
  • 18
  • Use a form. Here is a good example: [another_answer](http://stackoverflow.com/a/13001878/1489912) – Manatax Jun 09 '16 at 17:57
  • 1
    I am using angularjs...and not javascript...thanks for the reference. – Israel Meshileya Jun 09 '16 at 18:09
  • angular.js is a javascript library my friend.... – Manatax Jun 09 '16 at 18:13
  • 1
    kind of new to it...but i am also using form in my html...but the problem now is to use the data on different pages.... i.e, the data i get as a response..whenever i post to a particular url – Israel Meshileya Jun 09 '16 at 18:17
  • 1
    That is why I said that. In order to pass the data to a different page (not your single page app) you need to use a form. If you want to pass data from one page of your angular app to another page of your same angular app, then use a factory service. – Manatax Jun 09 '16 at 18:22
  • okay, thanks so much for this...i am enlightened by this illustration of yours...my major challenge is that, i do not have access to this data..because, i will receive it as a response, after sending a request to a URL...so, it's this response i will use in another page....and @Rahul suggested i use sessionStorage or localStorage... – Israel Meshileya Jun 09 '16 at 18:36
  • You can certainly use sessionstorage or localstorage for local storage. Think about it as a bigger cookie. But the point in fact is that because you are making a single page app, your data can be passed from one place to another through services. go to the angularjs.org tutorials/documentation and give it a good study. There is more to Angular and single page applications than you think. – Manatax Jun 09 '16 at 19:06
  • ..really appreciates this extended illustration of yours...and i will check the url been sent..but, the application is not a single page app...i have several pages to use the data been sent back as a response...after a user logs in...if i get tucked up...will check back on you..and you can share with me some ideas to better this mobile application using angularjs too..i will really appreciate. – Israel Meshileya Jun 09 '16 at 19:11
  • As I said before... if you are NOT building a Single Page App, and you want to send the information to a different URL, then use forms. If you are sending the information to a different page on the same URL on a multiple page app, then localstorage is a good option. If you want to send the information to multiple other pages while you continue to stay in your current page, then you can use the same $http you used before. – Manatax Jun 09 '16 at 19:53
  • ..thanks so much for your response, i have been able to figure it out....i do not know, if you have idea on using monaca – Israel Meshileya Jun 14 '16 at 11:21

1 Answers1

2

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

Rahul Malu
  • 556
  • 2
  • 9
  • is it possible for me to use a page to carry out different functions (sending different forms)...because, the purpose of the application is to send different data on different pages – Israel Meshileya Jun 09 '16 at 18:08
  • Forms are submitted to a web server. The web server will respond with a webpage. Along with the webpage the server can send the details inside the html (details posted via Form). You can not directly submit a Form to a webpage. – Rahul Malu Jun 09 '16 at 18:16
  • thanks for the explanation, what i am thinking of presently is how to use the data i get back as a response (after posting my request to a url) in another html page. because, if i am to send my other request, i am to include some of the data gotten from the previous request i sent. – Israel Meshileya Jun 09 '16 at 18:21
  • You can also try storing the details you got from the first request into sessionStorage or localStorage. You will be able to access them in next pages of your website. Eg: set value in localStorage from Page1 localStorage.setItem("username" , "Rahul"); Get value from localStorage inside Page2 var username = localStorage.getItem("username"); – Rahul Malu Jun 09 '16 at 18:24
  • got somethings on the sessionStorage, but kind of confused in implementing it with my script up there...and the main aim of this app is to be converted to an apk or ios file...i hope my aim will also be accomplished with this. – Israel Meshileya Jun 09 '16 at 18:33