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

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

问题描述

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

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

假设我有一个登录页面(用户名/密码),在成功验证后,我会看到主页.现在登录和主页屏幕实际上应该是一个页面的一部分.

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.

如何设计这样的页面?

推荐答案

这是一个如此广泛的问题,以至于可以写整本书来详细回答它.

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天全站免登陆