Home Backend Development PHP Tutorial PHP+ajax implements a news message system without refreshing (with source code)_PHP tutorial

PHP+ajax implements a news message system without refreshing (with source code)_PHP tutorial

Jul 13, 2016 am 10:50 AM
ajax jquery php+ajax accomplish news Source code message of Simple system

Ajax has been very simple and easy to implement since jquery was introduced. Now I will introduce the implementation process of a refresh-free news message system based on jquery ajax+php mysql. I hope this article can help you.

The most concise and easy-to-understand ajax message system without refreshing, the source code omits the process of accepting data verification. Readers can expand it according to their own needs.


Core source code:


1. Configuration file: config.php

The code is as follows Copy code
 代码如下 复制代码


//数据库配置信息(用户名,密码,数据库名,表前缀等)

$cfg_dbhost = "localhost";

$cfg_dbuser = "root";

$cfg_dbpwd = "root";

$cfg_dbname = "ajaxdemo1";

$cfg_dbprefix = "";


$link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);

mysql_select_db($cfg_dbname);

mysql_query("set names utf8");

?>

代码如下 复制代码


header("Content-type:text/html;charset=utf-8");

include "config.php";

//post接收数据,只是演示效果,这里就省去验证了

$name = $_POST['name'];

$content = $_POST['content'];


$sql = "insert into test (name,content) values ('{$name}','{$content}');";

$res = mysql_query($sql,$link);

if($res){

echo '{"name": "'.$name.'","content": "'.$content.'","status": "1"}';

}

?>

//Database configuration information (user name, password, database name, table prefix, etc.) $cfg_dbhost = "localhost"; $cfg_dbuser = "root"; $cfg_dbpwd = "root"; $cfg_dbname = "ajaxdemo1"; $cfg_dbprefix = ""; $link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd); mysql_select_db($cfg_dbname); mysql_query("set names utf8"); ?> 2. Process the request: deal.php
The code is as follows Copy code
<🎜> header("Content-type:text/html;charset=utf-8");<🎜> <🎜> include "config.php";<🎜> <🎜> //Post receives data, just to demonstrate the effect, no verification is needed here <🎜> <🎜> $name = $_POST['name'];<🎜> <🎜> $content = $_POST['content'];<🎜> <🎜> <🎜> <🎜><🎜> $sql = "insert into test (name,content) values ​​('{$name}','{$content}');";<🎜> <🎜> $res = mysql_query($sql,$link);<🎜> <🎜> if($res){<🎜> <🎜> echo '{"name": "'.$name.'","content": "'.$content.'","status": "1"}';<🎜> <🎜>}<🎜> <🎜>?>

3.首页代码:index.php

 代码如下
 代码如下 复制代码

无刷新

 


 

  用户名:

  内 容:

  

 

 include "config.php";

 $sql = "select * from test;";

 $res = mysql_query($sql,$link);

 while($row=mysql_fetch_array($res)){

  echo "

".$row['name']." 发表了:".$row['content']."

";

 }

?>

复制代码

 代码如下 复制代码


DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

无刷新  
 
  用户名:
  内  容:       
".$row['name']." 发表了:".$row['content']."

";  } ?>
数据库文件
 代码如下 复制代码

DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(64) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8; 源码下载地址:php+ajax实现无刷新的新闻留言系统下载

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632619.htmlTechArticleAjax has been very simple and easy to implement since jquery was introduced. Let me introduce an ajax+php based on jquery MySQL's non-refresh news message system implementation process, I hope this article can bring you...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CUDA's universal matrix multiplication: from entry to proficiency! CUDA's universal matrix multiplication: from entry to proficiency! Mar 25, 2024 pm 12:30 PM

General Matrix Multiplication (GEMM) is a vital part of many applications and algorithms, and is also one of the important indicators for evaluating computer hardware performance. In-depth research and optimization of the implementation of GEMM can help us better understand high-performance computing and the relationship between software and hardware systems. In computer science, effective optimization of GEMM can increase computing speed and save resources, which is crucial to improving the overall performance of a computer system. An in-depth understanding of the working principle and optimization method of GEMM will help us better utilize the potential of modern computing hardware and provide more efficient solutions for various complex computing tasks. By optimizing the performance of GEMM

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

On July 29, at the roll-off ceremony of AITO Wenjie's 400,000th new car, Yu Chengdong, Huawei's Managing Director, Chairman of Terminal BG, and Chairman of Smart Car Solutions BU, attended and delivered a speech and announced that Wenjie series models will be launched this year In August, Huawei Qiankun ADS 3.0 version was launched, and it is planned to successively push upgrades from August to September. The Xiangjie S9, which will be released on August 6, will debut Huawei’s ADS3.0 intelligent driving system. With the assistance of lidar, Huawei Qiankun ADS3.0 version will greatly improve its intelligent driving capabilities, have end-to-end integrated capabilities, and adopt a new end-to-end architecture of GOD (general obstacle identification)/PDP (predictive decision-making and control) , providing the NCA function of smart driving from parking space to parking space, and upgrading CAS3.0

How to implement dual WeChat login on Huawei mobile phones? How to implement dual WeChat login on Huawei mobile phones? Mar 24, 2024 am 11:27 AM

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Jun 02, 2024 pm 02:58 PM

On April 11, Huawei officially announced the HarmonyOS 4.2 100-machine upgrade plan for the first time. This time, more than 180 devices will participate in the upgrade, covering mobile phones, tablets, watches, headphones, smart screens and other devices. In the past month, with the steady progress of the HarmonyOS4.2 100-machine upgrade plan, many popular models including Huawei Pocket2, Huawei MateX5 series, nova12 series, Huawei Pura series, etc. have also started to upgrade and adapt, which means that there will be More Huawei model users can enjoy the common and often new experience brought by HarmonyOS. Judging from user feedback, the experience of Huawei Mate60 series models has improved in all aspects after upgrading HarmonyOS4.2. Especially Huawei M

PHP Programming Guide: Methods to Implement Fibonacci Sequence PHP Programming Guide: Methods to Implement Fibonacci Sequence Mar 20, 2024 pm 04:54 PM

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones How to implement the WeChat clone function on Huawei mobile phones Mar 24, 2024 pm 06:03 PM

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

How to leave a message on Xianyu How to leave a message on Xianyu and chat privately How to leave a message on Xianyu How to leave a message on Xianyu and chat privately Mar 23, 2024 am 09:10 AM

Xianyu APP is a super second-hand trading software. It allows everyone to choose products here at will, or publish their own products for sale. There is no problem. Everything can be realized here. When you use it here When using the Xianyu APP, everyone needs to communicate in a timely manner by leaving messages to get more information and help you sell or buy goods better. It is relatively convenient and is aimed at those who still don’t know how to leave messages on Xianyu. For my friends, I have now brought you specific Xianyu message tutorials. I hope it will be helpful to you. Xianyu message tutorial: 1. First, open Xianyu. 2. Then enter the interface and click on a product. 3. Then in the interface that appears, slide up and click

Differences and similarities of cmd commands in Linux and Windows systems Differences and similarities of cmd commands in Linux and Windows systems Mar 15, 2024 am 08:12 AM

Linux and Windows are two common operating systems, representing the open source Linux system and the commercial Windows system respectively. In both operating systems, there is a command line interface for users to interact with the operating system. In Linux systems, users use the Shell command line, while in Windows systems, users use the cmd command line. The Shell command line in Linux system is a very powerful tool that can complete almost all system management tasks.

See all articles