Php+ajax implementation of non-refreshed news message system, AJAX message system
This article introduces a non-refreshing news message system, the most concise and easy to understand an AJAX non-flush message system, the source code is omitted to accept the data validation process, we can expand according to their own needs, the following into the topic.
Core Source:
1. Configuration file: config.php, the code is as follows:
<?php //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);
2. Processing the request: deal.php, the code is as follows:
<?php Header ("Content-type:text/html;charset=utf-8"); Include "config.php"; POST receive data, just demo effect, here is omitted to verify $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. Home code: index.php, the code is as follows:
No refresh
<?php include "config.php"; $sql = "SELECT * from Test;"; $res = mysql_query ($sql, $link); while ($row =mysql_fetch_array ($res)) { echo "". $row [' name ']." Published: ". $row [' content ']."
"; } ? >
Database file with the following code:
DROP TABLE IF EXISTS ' test '; CREATE TABLE ' test ' ( ' id ' int (ten) unsigned NOT NULL auto_increment, ' name ' varchar ($) NOT NULL, ' content ' te XT Not NULL,
The above is for everyone to share the php+ajax to achieve a non-refreshed news message system, I hope that everyone's learning has helped.
http://www.bkjia.com/PHPjc/1065585.html www.bkjia.com true http://www.bkjia.com/PHPjc/1065585.html techarticle Php+ajax Implementation of non-refreshed news message system, AJAX message system This article introduced a non-refreshing news message system, the most concise and easy to understand an AJAX without refreshing message system, the source of the province ...