Implement the registration function in ajax mode (submit data to the background database for interaction), ajax background

Source: Internet
Author: User

Implement the registration function in ajax mode (submit data to the background database for interaction), ajax background

1. When we verify the form, we usually set this to prevent errors from being sent to the server as well:

$ (Function () {var isusername; (set a variable) var ispwd; $ ('form'). submit (function (e) {if (! Isusername |! Ispwd) {e. preventDefault (); (the default event to block events )})});

1. In nodejs, we can use the following method to (load) Jump to the page:
In JQuery, load () is used to load a page.
Window. location () This is to jump to a specified page in windows

Ii. Steps for installing MongoDB in node. js and related operations:
1. Download the installer. (Windows XP can only use versions earlier than 2.2, Windows 7 or above can use the latest version): http://www.mongodb.org/downloads
2. start installing MongoDB. For Windows XP, you can directly copy the installation directory to the specified directory. If Windows 7 runs the installer, you can select the installation path. (Note that the installation path should not contain Chinese characters) the installed MONgoDB is in C: \ Program Files \ MongoDB \ Server \ 3.2 \ bin by default.
3. Create a data directory under the same directory installed, and then create the db directory and log directory in the data directory.
4. Enter cd C: \ Program Files \ MongoDB \ Server \ 3.2 \ bin in the command line, and then enter mongo. Go to the cmd.exe operation interface.
5. Start running MongoDB. Run the following command to install the MongoDB program to the windows service.
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" -- install
6.in cmd.exe, we can add, delete, modify, and query objects. The following describes the operations in sequence.
Before that, we can use show dbs to view all the databases in the current mongo. If no database exists, use f30. (First, check whether there is F30. If no database exists, create a database named f30)
1> Add: db. users. insert ({maen: 'dd', age: 20 })
After the increase, you may use db. users. find () to check whether the increase 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}) to change the age of the name dd to 22.
4> Search: db. users. find ({age: {$ gt: 20}) to find data larger than 20

3. You can submit data by clicking the BUTTON and jump to the logon page. The Code is as follows:

$ ("Input [type = button]"). click (function (e) {if (! IsUsernameValid |! IsPwdValid) {// when the user name or password is false, a message box is displayed, prompting you to enter the correct information. Alert ('Enter the correct information'); return; // end} $. ajax ({// use ajax to update data type: "post" without refreshing the webpage, // request url: "/users/reg", // path data: {username: $ ("input [name = username]"). val (), // obtain the value pwd: $ ("input [name = pwd]") for username in input. val () // obtain the value of pwd in input}, success: function () {alert ("registered successfully"); window. location = "login.html"; // log on to login.html after successful registration }});})

The above code is to use ajax 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.