Use Ajax to submit data to the backend database and interactive functions

Source: Internet
Author: User
Tags install mongodb

How to use Ajax to submit data to the background database, and complete the interaction?????
First, when we verify the form, in order to prevent the error is also sent to the server, we usually set up:
$ (function () {
var Isusername; (Set a variable)
var ispwd;
$ (' form '). Submit (function (e) {
if (!isusername | |!ispwd) {
E.preventdefault (); (default event blocking event)
})
});
1, in the Nodejs we can use the following methods to (load) jump page:
The load in JQuery () This is the implementation of loading a page
Window.location () This is the jump to a specified page under Windows

Ii. the installation steps and related operations of MongoDB in node. JS:

1. Download the installer. (Windowxp can only use the previous version of 2.2, the latest version of the system window7 above): Http://www.mongodb.org/downloads

2. Start the installation of MongoDB. If it is 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 the 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 as the installation, and then create the DB directory and the log directory in the data directory.
4. On the command line, enter CD C:\Program files\mongodb\server\3.2\bin carriage return
then enter MONGO. Perform the Mongo.exe operation interface.
5. Start to run MongoDB. You can install MongoDB programs into Windows services 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 the Mongo.exe we can complete the increase, deletion, change, check: The following is introduced in turn
Before that we can use show DBS to see all the databases in the current MONGO, if not the use of F30 (first to find if there is no F30, if not automatically create a database named F30)
1> added: Db.users.insert ({maen: ' dd ', age:20})
Increased, may use Db.users.find () to see if the increase in success
2> Delete: Db.users.remove ({maen: ' dd '}) or Db.users.remove ({}) (this is to remove all data from the users)
3> Modify: Db.users.update ({maen: ' dd '},{age:22}) change the age of the name DD to 22
4> Find: Db.users.find ({age:{$gt: 20}) find data greater than 20

Third, we can submit the data via 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 if the user name or password has a false when a message box pops up and prompts: Please enter the correct information.
Alert (' Please enter the correct information ');
Return End
}
$.ajax ({//using AJAX to implement updating data without refreshing the page
Type: "POST",//Request method
URL: "/users/reg",//Path
data:{
username:$ ("Input[name=username]"). Val (),//Gets the value of name username in input
pwd:$ ("input[name=pwd]"). Val ()//Get the value of name pwd in input
},
Success:function () {
Alert ("Registered success");
window.location = "login.html"; Register successfully jump to login.html
}
});

})

The above code is to use the Ajax way to implement the registration function. Personal saying: Progress a little every day, believe that success is a ready person!!!

Use Ajax to submit data to the backend database and interactive functions

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.