


Detailed explanation of the example of message board function implemented by Ajax and mysql data interaction
This article mainly shares with you a detailed example of the message board function implemented by Ajax and MySQL data interaction. Recently, I made a small demo to realize the data interaction between Ajax and MySQL. The js part uses jq, and the background uses PHP. The database is mysql, and a node+MongoDB version will be available later.
I won’t go into details about the use and installation of mysql. Baidu xampp, Apache server and mysql database are integrated by myself, which is very easy to use.
First open the server and database. I established them here first. An "eleven" database, with a table called microblog created below (please note: I am using a higher version of mysql here, and the PHP database linking methods use mysqli_. If the version is too low, please use the mysql_ method. Modify the code yourself)
The following is the code part:
html page and js part:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>微博留言板</title> <style type="text/css"> *{ margin: 0; padding: 0; } #box{ width: 600px; /*height: 500px;*/ border: 2px solid rgb(85,85,85); border-radius: 15px; margin: 50px auto; padding: 20px 10px 15px; background-color: rgb(85,85,85); } #content{ display: block; resize: none; width: 550px; height: 200px; margin: 0 auto; border: 2px solid rgb(225,225,225); border-radius: 10px; text-align: center; font-size: 30px; background-color: rgb(225,225,225); } #content:focus{ outline: none; border: 2px solid rgb(225,225,225); box-shadow: 0 0 15px rgb(225,225,225); } #btn{ border: 2px solid rgb(255,204,0); width: 80px; height: 40px; border-radius: 5px; margin-top: 30px; font-size: 17px; cursor: pointer; outline: none; background-color: rgb(255,204,0); } .list{ list-style: none; background-color: rgb(249,249,249); margin-top: 20px; } .list>li{ padding: 20px 10px 10px; border-bottom: 2px solid rgb(68,68,68); font-size: 20px; color: rgb(200,214,225); position: relative; word-break: break-word; word-wrap: break-word; background-color: rgb(85,85,85); } .list>li>.control{ position: absolute; bottom: 3px; right: 5px; font-size: 14px; } .list>li>p{ margin-bottom: 25px; } .control span,.control em{ display: inline-block; margin-right: 15px; } .control em{ color: darkblue; cursor: pointer; } a{ text-decoration: none; color: darkred; } #page>a{ display:inline-block; width: 40px; height: 30px; margin-top: 10px; text-align: center; line-height: 30px; font-size: 20px; border-radius: 5px; color: white; background-color: rgb(51,21,70); } #head{ color: rgb(200,214,225); font-size: 30px; height: 50px; border-bottom: 2px solid rgb(68,68,68); margin-bottom: 20px; } </style> </head> <body> <p id="box"> <p id="head"> 留言板 </p> <p id="fill_in"> <textarea id="content"></textarea> <button id="btn">提交留言</button> </p> <!--留言列表--> <p id="message_text"> <ul class="list"> </ul> </p> <!--分页--> <p id="page"> <a href="javasript:void(0)">1</a> <a href="javasript:void(0)">2</a> </p> </p> </body> <script src="Jq/jquery-3.1.1.min.js"></script> <script type="text/javascript"> $(function(){ $("#btn").on("click",function(){ if ($("#content").val() == "") { alert("~~客官,说一句再走呗~~
Related recommendations:
Detailed explanation of Ajax and php data interaction
WeChat applet wx.request realizes background data interaction function analysis
Related data monitoring and A small example of data interaction
The above is the detailed content of Detailed explanation of the example of message board function implemented by Ajax and mysql data interaction. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL query performance can be optimized by building indexes that reduce lookup time from linear complexity to logarithmic complexity. Use PreparedStatements to prevent SQL injection and improve query performance. Limit query results and reduce the amount of data processed by the server. Optimize join queries, including using appropriate join types, creating indexes, and considering using subqueries. Analyze queries to identify bottlenecks; use caching to reduce database load; optimize PHP code to minimize overhead.

Backing up and restoring a MySQL database in PHP can be achieved by following these steps: Back up the database: Use the mysqldump command to dump the database into a SQL file. Restore database: Use the mysql command to restore the database from SQL files.

How to insert data into MySQL table? Connect to the database: Use mysqli to establish a connection to the database. Prepare the SQL query: Write an INSERT statement to specify the columns and values to be inserted. Execute query: Use the query() method to execute the insertion query. If successful, a confirmation message will be output.

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

To use MySQL stored procedures in PHP: Use PDO or the MySQLi extension to connect to a MySQL database. Prepare the statement to call the stored procedure. Execute the stored procedure. Process the result set (if the stored procedure returns results). Close the database connection.

Creating a MySQL table using PHP requires the following steps: Connect to the database. Create the database if it does not exist. Select a database. Create table. Execute the query. Close the connection.

Oracle database and MySQL are both databases based on the relational model, but Oracle is superior in terms of compatibility, scalability, data types and security; while MySQL focuses on speed and flexibility and is more suitable for small to medium-sized data sets. . ① Oracle provides a wide range of data types, ② provides advanced security features, ③ is suitable for enterprise-level applications; ① MySQL supports NoSQL data types, ② has fewer security measures, and ③ is suitable for small to medium-sized applications.

Ajax (Asynchronous JavaScript and XML) allows adding dynamic content without reloading the page. Using PHP and Ajax, you can dynamically load a product list: HTML creates a page with a container element, and the Ajax request adds the data to that element after loading it. JavaScript uses Ajax to send a request to the server through XMLHttpRequest to obtain product data in JSON format from the server. PHP uses MySQL to query product data from the database and encode it into JSON format. JavaScript parses the JSON data and displays it in the page container. Clicking the button triggers an Ajax request to load the product list.
