简体   繁体   English

JavaScript:登录和注册系统

[英]JavaScript : Login And Registration System

I want to make a Login And Registration Form not using PHP & MySQL.我想制作一个不使用 PHP 和 MySQL 的登录和注册表单。 But using JavaScript instead.但是改用 JavaScript。 Maybe using JavaScript & MySQL or maybe something else that's easier than using PHP.也许使用 JavaScript 和 MySQL 或者其他比使用 PHP 更容易的东西。 Anybody know a JavaScript source code for Login And Registration System?有人知道登录和注册系统的 JavaScript 源代码吗? Please Help :)请帮助:)

You cannot use javascript to send data to a mysql database directly.您不能使用 javascript 直接将数据发送到 mysql 数据库。 But, you can use AJAX(Asynchronous Javascript And XML) to send the data to a .php file and the php file will process the data and will give a response and AJAX will display the response in a html <div> element.但是,您可以使用 AJAX(异步 Javascript 和 XML)将数据发送到.php文件,php 文件将处理数据并给出响应,AJAX 将在 html <div>元素中显示响应。 I have written some code below as to show how you can perform an AJAX request.我在下面编写了一些代码来展示如何执行 AJAX 请求。 Here i am using the GET method.这里我使用的是GET方法。 You can do this with or without jQuery:您可以使用或不使用 jQuery 来执行此操作:

With jQuery:使用 jQuery:

$(document).ready(function() {
    $("button").click(function() {
        $.ajax({
            type : 'GET',
            url  : "server.php",
            data : {
                // Data you want to submit to the server
            },
            success : function() {
                // code to be executed when the request was successful
            }
            error : function() {
                // code to be executed when an error occurs
            }
        });
    });    
});

Without jQuery:没有 jQuery:

HTML: HTML:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Document</title>
</head>
<body>

<button onclick="submitData()">Submit</button>
<!-- Attach an onclick event to the button -->
<p id="response"></p>

</body>
</html>

JavaScript: JavaScript:

var xhr = new XMLHttpRequest();

function submitData() { // define the function to be called when the button is clicked
    xhr.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("response").innerHTML = 
            this.responseText;
        }
    };
    xhr.open("GET", "server.php", true);
    xhr.send();
}

I hope this answer helps your question.我希望这个答案对你的问题有所帮助。

JavaScript and MySQL is a deadly combination. JavaScriptMySQL是一个致命的组合。

JavaScript is a client side language and it cannot communicate with MySQL database without communicating with any server side language. JavaScript 是一种客户端语言,如果不与任何服务器端语言进行通信,它就无法与MySQL 数据库进行通信。

So here is how you can make things, send data from client (JavaScript) to server (PHP or any other Server side language) and then store/retrieve data in MySQL.因此,您可以通过以下方式进行操作,将数据从客户端 (JavaScript) 发送到服务器(PHP 或任何其他服务器端语言),然后在 MySQL 中存储/检索数据。

And return response to client from server using server-side language.并使用服务器端语言从服务器向客户端返回响应。

So, in short to do processing on MySQL database there must be a server side language to allow communication between client and database.因此,简而言之,要在 MySQL 数据库上进行处理,必须有一种服务器端语言来允许客户端和数据库之间进行通信。

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

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