Ajax way to implement the registration function (submit data to the background database to complete the interaction) _ajax related

Source: Internet
Author: User
Tags mongodb

First, when we are validating the form, in order to prevent the wrong also sent to the server, we usually set this:

   $ (function () {
    var isusername; (set a variable)
    var ispwd;
     $ (' form '). Submit (function (e) {
       if (!isusername | |!ispwd) {
         e.preventdefault (); (Block event default event)
      })
   });

1, in the Nodejs we can use the following methods to (load) jump page:
The load in JQuery () This is implemented to load a page
window.location () This is to jump to a specified page under Windows

The installation steps and related operation of MongoDB in Node.js:
1. Download the installer. (Windowxp can only use the previous version of 2.2, window7 above system may use the latest version) download address: http://www.mongodb.org/downloads
2. Start installation of MongoDB. If you are an XP system, you can copy the installation directory directly to the specified directory. If the Win7 system runs the setup program, you can choose the installation path yourself. (Note installation path does not appear in Chinese) installed MongoDB default in C:\Program Files\mongodb\server\3.2\bin
3. Create a directory data in the same directory that is installed, and then create the DB directory and log directory in the data directory.
4. Enter the CD C:\Program files\mongodb\server\3.2\bin carriage return in the command line and enter the MONGO. Perform the Mongo.exe operation interface.
5. Start running MongoDB. You can install a MongoDB program into a Windows service by using the following command.
Finally, open the command line and switch to the MongoDB bin directory. Run:
mongod.exe--dbpath "c:\data\db"--logpath "C:\data\log\mongodb.log"--install
6. In Mongo.exe we can complete the increase, delete, change, check: The following is introduced in turn
Before that we can use the show DBS to view all the databases in the current MONGO, and if not, use using F30 (first find out if there is F30, and automatically create a database named F30 if not)
1> Add: Db.users.insert ({maen: ' dd ', age:20})
After the increase, may use Db.users.find () to see whether to increase the success
2> Delete: Db.users.remove ({maen: ' dd '}) or Db.users.remove ({}) (this is to delete all data in the users)
3> Modification: db.users.update ({maen: ' dd '},{age:22}) modifies the age of the name DD to 22
4> Lookup: Db.users.find ({age:{$gt: 20}) Looking for data greater than 20

Third, we can submit the data through the button, and jump to the login interface, the code is as follows:

 $ ("Input[type=button]"). Click (function (e) {
 if (!isusernamevalid | |!ispwdvalid) {// Use the IF statement to determine that a message box pops up when a username or password is false and prompts: Please enter the correct information.
           alert (' Please enter the correct information ');
           return;  End
         }
         $.ajax ({       ///AJAX-based update data
           type: "POST",//Request method
           URL: "/users/reg",//path
           data : {
             username:$ ("Input[name=username]"). Val (),  //Get the value of name username in input
             pwd:$ ("input[name=pwd]") . val ()//Get value for name pwd in input
           },
           success:function () {
             alert ("registered successfully");
             window.location = "login.html"; Registration succeeds to jump to Login.html
           }}
         );
         
       

The above code is the Ajax way to implement the registration function.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.