Php+ajax implementation of non-refreshed news message system, AJAX message System _php Tutorial

Source: Internet
Author: User

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 ...

  • 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.