单页应用程序架构(JavaScript) [英] Architecture for single page application (JavaScript)

本文介绍了单页应用程序架构(JavaScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解设计单页应用程序(主要是通过JavaScript)的整体架构。

I wanted to understand the overall architecture for designing single page application (mainly through JavaScript)

假设我有一个登录页面(Usernam / Password)并且成功认证,我显示了主页。现在登录和主页屏幕实际上应该是单页的一部分。

Let's say I have a login page (Usernam/Password) and on successful authentication, I am shown the homepage. Now both the login and homepage screens should actually be part of a single page.

我如何设计这样的页面?

How can I design such kind of page?

推荐答案

这是一个广泛的问题,整本书都可以写成详细回答。

This is such a broad question that entire books could be written to answer it in detail.

基本上你需要做的是使用AJAX而不是页面重新加载。您仍然需要连接到服务器来验证用户,而不是每次执行整个页面时重新加载整个页面,您需要对您的服务器进行AJAX调用,并且取决于登录是否成功或不会更改内容的某些部分在页面上(如将登录按钮更改为以用户xxx身份登录消息等)。

Basically what you need to do is to use AJAX instead of page reloads. You still need to connect to the server to authenticate users but instead of reloading the entire page every time you do it, you need to make an AJAX call to your server and depending on whether the login was successful or not change some parts of the content on the page (like changing the Login button to a "Logged in as user xxx" message etc.).

这篇关于单页应用程序架构(JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆