Home > Web Front-end > JS Tutorial > body text

Ajax submits data to the backend database to implement user registration

php中世界最好的语言
Release: 2018-04-03 17:16:14
Original
2465 people have browsed it

This time I will bring you ajax to submit data to the backend database to implement user registration, ajax to submit data to the backend database to implement user registrationWhat are the precautions, the following is the actual combat Let’s take a look at the case.

1. When we are validating the form, in order to prevent errors from being sent to the server, we usually set it like this:

   $(function(){
    var isusername;(定一个变量)
    var ispwd;
     $('form').submit(function(e){
       if(!isusername || !ispwd){
         e.preventDefault();(阻止事件的默认事件)
      })
   });
Copy after login

1. In nodejs we can use the following method ( Loading) jump page:
load() in JQuery This is to load a page
window.location() This is to jump to a page under windows Specified page

2. Installation steps and related operations of MongoDB in node.js:
1. Download the installation program. (window If it is an XP system, you can directly copy the installation directory to the specified directory. If you run the installation program on win7 system, you can choose the installation path yourself. (Note that the installation path does not appear in Chinese) The installed MONgoDB defaults to C:\Program Files\MongoDB\Server\3.2\bin
3. Create a directory data in the same directory as the installation, and then create db in the data directory directory and log directory.
4. In the command line, enter cd C:\Program Files\MongoDB\Server\3.2\bin and press Enter, then enter mongo. Enter the mongo.exe operation interface.
5. Start running MongoDB. You can install the MongoDB program into the Windows service through the following command.
Finally open the command line and switch to the bin directory of MongoDB. Run:

mongod.exe --dbpath "c:\data\db" --logpath "c:\data\log\mongodb.log" --install6. In mongo In .exe, we can complete addition, deletion, modification and query: the following introduction is in order
Before this, we can use show dbs to view all databases in the current mongo. If not, use use f30 (first check if there is F30, If not, a database named f30 will be automatically created)
1>Add: db.users.insert({maen:'dd',age:20})
After adding, you may use db.users.find () to see if the addition is successful
2>Delete: db.users.remove({maen:'dd'}) or db.users.remove({}) (This is to delete all data in users)
3>Modify: db.users.update({maen:'dd'},{age:22}) Modify the age of the name dd to 22
4>Find: db.users.find({age:{ $gt:20}) Find data greater than 20

3. We can submit data through BUTTON and jump to the login interface. The code is as follows:

 $("input[type=button]").click(function(e){
 if(!isUsernameValid || !isPwdValid){ //用if语句来判断当用户名或者密码有一个为false时就弹出一个消息框,并提示:请输入正确的信息。
           alert('请输入正确的信息');
           return;  //结束
         }
         $.ajax({       //用ajax来实现不刷新网页的基础上更新数据
           type:"post", //请求方式
           url:"/users/reg", //路径
           data:{
             username:$("input[name=username]").val(),  //获取input中name为username的值
             pwd:$("input[name=pwd]").val() //获取input中name为pwd的值
           },
           success:function(){
             alert("注册成功");
             window.location = "login.html"; //注册成功就跳转到login.html
           }
         });
         
       })
Copy after login
I believe you have read the case in this article You have mastered the method. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How to achieve secondary linkage with Ajax combined with PHP

js+ajaxcap operates json objects to loop to the table save

The above is the detailed content of Ajax submits data to the backend database to implement user registration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template