This article introduced a no refreshing news message system, the most concise and understandable an AJAX no refresh message system, the source code omitted the process of accepting data validation, we can expand according to their needs, the following into the theme.
Core Source:
1. Configuration file: config.php, the code is as follows:
<?php
//Database configuration information (username, 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. Processing request: Deal.php, the code is as follows:
<?php
Header ("Content-type:text/html;charset=utf-8");
Include "config.php";
The POST receives the data, only demonstrates the effect, here eliminates the verification
$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, code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Database file with the following code:
DROP TABLE IF EXISTS ' test ';
CREATE TABLE ' test ' (
' id ' int (a) unsigned NOT null auto_increment,
' name ' varchar ' (+) not NULL,
' content ' te XT not NULL,
PRIMARY KEY (' id ')
) Engine=myisam DEFAULT Charset=utf8;
The above is for you to share the php+ajax to achieve no refreshing news message system, I hope to help you learn.