使用javascript注册和登录网站

Website Signup and Login using javascript?

本文关键字:登录 网站 注册 javascript 使用      更新时间:2023-09-26

我不知道如何在JavaScript中存储注册和登录详细信息。我使用php和数据库来存储我以前项目的信息,所以我不知道如何用JavaScript来做。

以下是注册html代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Registration</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="keywords" content="Game Website Template, free templates,
             website templates, CSS, XHTML" />
<meta name="description" content="Game Website Template - download free 
            XHTML/CSS files from templatemo.com" />
<link href="templatemo_style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="templatemo_wrapper_outer">
<div id="templatemo_wrapper_inner">
    <div id="templatemo_banner"></div> <!-- end of banner -->
    <div id="templatemo_menu">
        <ul>
            <li><a href="index.php">Home</a></li>
            <li><a href="Game.php">Games</a></li>
            <li><a href="My Profile.php">Profile</a></li>
            <li><a href="#">Download</a></li>
            <li><a href="#">Contact</a></li>
        </ul>
    </div> <!-- end of menu -->
<h1> Online game shop </h1>
<h2> Enter the details bellow. </h2>
<form method ="POST" action = "PHP.php" >
<h9> *Compulsory fields    </h9>
<br>
<br>
 *First Name <input type="text" name="fname" 
           class="form-control" placeholder="First Name" required/> <br>
<br>
 *Last Name  <input type= "text" name="lname" 
         class ="form-control" placeholder="Last Name" required/>
<br>
<br>
 *E-mail Address <input type="email" name="Eadd"class="form-control" 
           placeholder="E-mail Address" required/> 
<br>
<br>
 *Mobile number <input type="int" max="10" min="10"name="Mnum" 
          class="form-control" placeholder="mobile Number" required/> 
<br>
<br>
 *Password <input type="password"name="pass" 
          class="form-control" placeholder="Password" required/> 
<br>
<br>
*Confirm Password <input type="password"name="Cpass" 
          class="form-control" placeholder="Confirm Password" required/> 
<br>
<br>
    *Gender <br>
<input type="radio" name="gen" value="m">Male<br>
 <input type="radio" name="gen" value="f">Female
<br>
<br>
<button type="submit" class="btn btn-default">Submit</button>
</div>
</form>
<div id="templatemo_footer">
        Copyright © 2048 <a href="#">Your Company Name</a> 
    </div> <!-- end of footer -->
</body>
</html>

请注意,上面的代码来自我以前的项目,仍然有php,所以我想删除php并存储用户使用javascript提供的信息。

任何帮助都将不胜感激!

这是服务器代码,但它只适用于名字字段,我尝试过,但失败了。

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class info extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
//String s, goods[] = {"Fifa 15", "Battlefield 5", "GTA 6"};
String name= req.getParameter("fname");
//int price []={10,20,30};
//int cost;
PrintWriter out = res.getWriter();
res.setContentType("text/html");
HttpSession session = req.getSession(true);
if ( session == null ) return;
//for (int i = 0; i < goods.length; i++)
//if ( session.getAttribute(name) != null )
session.setAttribute(name, new Integer(0) );
out.println("<html><body><h2>You are Registered !! </h2><ul>");

out.println("</ul></body></html>");
}
}

您不能仅使用JavaScript存储登录详细信息。如果您想使用JavaScript进行服务器调用,可以使用node.js。否则,您将需要将登录详细信息传递给PHP,这可以通过表单提交或AJAX调用来完成。

您不能使用客户端语言进行服务器端脚本编写。。如果您想使用javascript,请使用node.js或其他东西。为了澄清起见,javascript在用户浏览器中运行,对HTML/CSS的所有更改都在客户端浏览器中进行,而php在将HTML发送到客户端之前在服务器上运行。阅读JavaScript

您可以用javascript进行质询响应,但仍然需要进行某种服务器调用。

在中创建质询响应标志