Use ajax to submit data to the background database and interactive functions.

Source: Internet
Author: User

Use ajax to submit data to the background database and interactive functions.

How can I use ajax to submit data to the background database and complete interaction ?????
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 (); (blocks the default event of an event)
})
});
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 press Enter.
Then input 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 without refreshing webpages
Type: "post", // Request Method
Url: "/users/reg", // path
Data :{
Username: $ ("input [name = username]"). val (), // obtain the value of username in input.
Pwd: $ ("input [name = pwd]"). val () // obtain the value of pwd whose name is input.
},
Success: function (){
Alert ("registered successfully ");
Window. location = "login.html"; // login.html
}
});

})

The above code is to use ajax to implement the registration function. Personal famous saying: make a little progress every day. I believe that success is a preparation person !!!

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.