简体   繁体   English

单页应用程序? 登录页面

[英]Single Page Application? Login Page

I'm a little new to programming and I'm still beginning on working with a lot of the languages. 我对编程还有些陌生,但我仍然开始使用许多语言。

Currently, I'm working on a project that requires me to create a login page. 目前,我正在一个需要我创建登录页面的项目中。 With a successful login, the page will change to an "Account Info" page; 成功登录后,页面将更改为“帐户信息”页面; however, this has to be a single page application. 但是,它必须是单页应用程序。 My professor specified that the server will have no concept of "page", and that moving from "Login" to "AccountInfo" will not change the page/URL. 我的教授指定服务器将没有“页面”的概念,并且从“登录”更改为“ AccountInfo”将不会更改页面/ URL。

How do I go about calling this? 我该如何打电话呢? We've done introduction into Angular JS, but he's never done a tutorial on single page applications. 我们已经完成了Angular JS的介绍,但他从未完成过有关单页应用程序的教程。

My .js for the login looks like this: 我的登录.js文件如下所示:

Home.LoginClick = function () {

    $.ajax({

        url: "Home/Login",

        data: {

            Username: $(".Username").val(),

            Password: $(".Password").val(),

        },

        success: function (result) { alert(result);
            if (deserializedData.Message == "Success")
                Home.ChangeToAccountInfo();
        }

    });
}

Single Page application means that the client loads all the HTML in one shot, thus preventing your browser to refresh the page every time you click somewhere or go a different page. 单页应用程序意味着客户端可以一次加载所有HTML,从而防止浏览器每次单击某处或转到其他页面时刷新页面。 You can witness this in action by going into most websites. 您可以访问大多数网站,亲眼目睹这一点。

It is considered best practices to use services for back end interaction. 使用服务进行后端交互被认为是最佳实践。 Therefore you should create a Auth. 因此,您应该创建一个Auth。 service managing your login. 服务管理您的登录信息。 Create a function login - and logout. 创建一个函数登录-并注销。 and then inject that service in your controller associated with the view thats displays the login form. 然后将该服务注入与显示登录表单的视图关联的控制器中。

You should upon submission of the form call this login function. 您应该在提交表单后调用此登录功能。 you can use ng-submit. 您可以使用ng-submit。 after submitting the form the function that you injected in your controller will check with you backend to see if the user exist or not and then you can redirect the user toward the page you want. 提交表单后,您在控制器中注入的功能将与您的后端进行核对,以查看用户是否存在,然后您可以将用户重定向到所需的页面。

You should look into the ui router for more details about how to handles your routes. 您应该查看ui路由器,以获取有关如何处理路由的更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM