Use the database and ajax method to write the map instance code, and use ajax to write the map instance

Source: Internet
Author: User

Use the database and ajax method to write the map instance code, and use ajax to write the map instance

Ajax tutorial

AJAX = Asynchronous JavaScript and XML (Asynchronous JavaScript and XML ).

AJAX is not a new programming language, but a new method that uses existing standards.

AJAX is the art of exchanging data with the server and updating some webpages without reloading the entire page.

Client: html, js, and css code:

<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN "" http://www.w3.org/TR/html4/loose.dtd "> <Html> Var express = require ("express"); // reference expressvar mysql = require ("mysql"); // reference mysqlvar app = express (); // execute the global function in express and return an express object app. configure (function () {app. use (app. router); // route, which is executed first When configuring a route. The user-defined interception address app. use (express. static (_ dirname + "/public"); // sets the static resource Path app. use (express. errorHandler (); // developer module that displays errors in html}); app. get ("/adress. do ", function (req, res) {// console. log ("d ----------- 1"); // create a database connection and build a bridge var myconn = m Ysql. createConnection ({host: "localhost", port: "3306", user: "root", password: "123456", database: "pet "}); // open the connection myconn. connect (); var SQL = "SELECT * FROM petmap"; // console. log (SQL); myconn. query (SQL, [], function (err, data) {// console. log (err); // console. log (data); res. send (data) ;}); // close the connection to myconn. end () ;}); // city click response app. get ("/adressMsg. do ", function (req, res) {var pmId = req. query. pmId; console. log (pmId); // create a database connection and build a bridge var Myconn = mysql. createConnection ({host: "localhost", port: "3306", user: "root", password: "123456", database: "pet "}); // open the connection myconn. connect (); console. log ("f ------------ 1"); var SQL = "SELECT * FROM petmap WHERE pmId =? "; Console. log (SQL); var id = parseInt (pmId); myconn. query (SQL, [id + 1], function (err, data) {console. log (err); console. log (data); res. send (data) ;}); // close the connection to myconn. end () ;}); // listening port number app. listen (8888, function () {// listens to the console. log ("express listening successful! "); Console. log (_ dirname );});

Mysql database information:

/* Create database: pet */create database pet;/* pet Shop map */create table petmap (/* pet shop */pmId INT AUTO_INCREMENT primary key, /* pet store id */pmName NVARCHAR (60),/* pet store name */pmCity NVARCHAR (20),/* city of pet store */pmAddress NVARCHAR (100 ), /* pet shop address */pmImg VARCHAR (60),/* Pet Shop image */pmPhone VARCHAR (30),/* pet shop phone number */pmTop FLOAT, /* pet store location above */pmLeft FLOAT/* pet store location below */)/* INSERT information */insert into petmap (pmName, pmCity, pmAddress, pmImg, pmPhone, pmTop, pmLeft) VALUES comment ', '2014-0335', 3076769); insert into petmap (pmName, pmCity, pmAddress, pmImg, pmPhone, pmTop, pmLeft) VALUES comment ', '2014-0451 ', 82516177); insert into petmap (pmName, pmCity, pmAddress, pmImg, pmPhone, pmTop, pmLeft) VALUES comment', '2014-80,625 ', 0891 );

Final result:

The above section describes how to write the map instance code through the database and ajax methods. I hope it will help you. If you have any questions, please leave a message, the editor will reply to you in a timely manner, and I would like to thank you for your support for the help House website!

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.