激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - PHP教程 - PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能示例

PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能示例

2019-10-14 13:51chengqiuming PHP教程

這篇文章主要介紹了PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能,結(jié)合實(shí)例形式分析了php+ajax實(shí)現(xiàn)的數(shù)據(jù)交互、數(shù)據(jù)庫(kù)連接、查詢(xún)等相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能。分享給大家供大家參考,具體如下:

一. 代碼

fun.js

function saveType(typename, username){
  if(typename==''){   //判斷博客類(lèi)別是否為空
    alert('請(qǐng)輸入類(lèi)別名稱(chēng)!');
  }else if(username==''){   //判斷用戶(hù)名是否為空
    alert('請(qǐng)輸入用戶(hù)名!');
  }else{
    var xmlObj;   //定義XMLHttpRequest對(duì)象
    var urlData = "typename="+typename+"&username="+username;    //指定要發(fā)送的數(shù)據(jù)
    if(window.ActiveXObject){   //判斷瀏覽器是否支持ActiveXObject組件,如支持則通過(guò)ActiveXObject方式創(chuàng)建XMLHttpRequest對(duì)象
      xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
    }else if(window.XMLHttpRequest){   //如果瀏覽器不支持ActiveXObject組件,則使用XMLHttpRequest組件創(chuàng)建XMLHttpRequest對(duì)象
      xmlObj = new XMLHttpRequest();
    }
    xmlObj.onreadystatechange = callBackFun;   //指定回調(diào)函數(shù)
    xmlObj.open("POST", "saveType.php", true);   //指定提交方法和頁(yè)面
    xmlObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");   //指定發(fā)送數(shù)據(jù)庫(kù)類(lèi)型
    xmlObj.send(urlData);   //指定發(fā)送的數(shù)據(jù)
    function callBackFun(){   //定義回調(diào)函數(shù)
      if(xmlObj.readyState == 4 && xmlObj.status == 200){   //如果服務(wù)器端返回內(nèi)容并無(wú)錯(cuò)誤發(fā)生
        if(xmlObj.responseText == 'y'){  //判斷保存是否成功,并給出提示
          alert('類(lèi)別添加成功!');
        }else{
          alert('類(lèi)別添加失敗!');
        }
      }
    }
  }
}

conn.php

<?php
$host = '127.0.0.1';
$userName = 'root';
$password = 'root';
$connID = mysql_connect($host, $userName, $password);
mysql_select_db('db_database27', $connID);
mysql_query('set names gbk');
?>

index.php

<?php
require_once 'conn.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加類(lèi)別</title>
<link rel="stylesheet" type="text/css" href="css/style.css" rel="external nofollow" rel="external nofollow" />
</head>
<script language="javascript" src="js/fun.js"></script>
<body>
<table border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td><img src="images/banner.gif" width="608" height="109" /></td>
 </tr>
</table>
<table width="200" height="7" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td></td>
 </tr>
</table>
<table width="608" height="200" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#7ED227">
 <tr>
  <td width="150" bgcolor="#F6FEFE" valign="top">
  <table width="150" border="0" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#D6FEFE">
   <?php
     $sql = mysql_query("select typename,username from tb_type order by addtime desc", $connID);
     $result = mysql_fetch_array($sql);
     if ($result){
       do{
   ?>
   <tr>
    <td bgcolor="#A6E617" height="20"><div align="center"><a href="#" rel="external nofollow" rel="external nofollow" class="a1"><?= $result['typename']?></a></div></td>
   </tr>
   <tr>
    <td bgcolor="#F2F2F2" height="12"><div align="left">發(fā)布人:
     <?= $result['username']?>
     </a></div></td>
   </tr>
   <?php
       }while($result = mysql_fetch_array($sql));
     }else{
   ?>
   <tr>
    <td bgcolor="#A6E617" height="20">暫無(wú)文章類(lèi)別</td>
   </tr>
   <?php
     }
   ?>
</table>
  </td>
  <td width="455" bgcolor="#FFFFFF" style="padding-left:30px; line-height:25px">
  請(qǐng)輸入博客類(lèi)別:<br />
      <input type="text" name="typename" size="30" id="typename" /><br /><br/>
  發(fā)布人:<br />
      <input type="text" name="username" size="30" id="username" /><br /><br/>
  <input type="button" value="保存" onclick="saveType(typename.value, username.value)" />
  </td>
 </tr>
</table>
<table width="200" height="7" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td></td>
 </tr>
</table>
<table width="608" height="70" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td background="images/bottom.gif"><div align="center">
   <DIV align="center">『博客』 版權(quán)所有 <a href="http://www.mingri***.com" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="a1">吉林省**科技有限公司</a>!  未經(jīng)授權(quán)禁止復(fù)制或建立鏡像!<BR>
     <BR>Copyright © <a href="http://www.mingri***.com" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="a1">www.mingri***.com</a> All Rights Reserved!<BR>
   </DIV>
  </div></td>
 </tr>
</table>
</body>
</html>

saveType.php

<?php
require_once 'conn.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>添加類(lèi)別</title>
<link rel="stylesheet" type="text/css" href="css/style.css" rel="external nofollow" rel="external nofollow" />
</head>
<script language="javascript" src="js/fun.js"></script>
<body>
<table border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td><img src="images/banner.gif" width="608" height="109" /></td>
 </tr>
</table>
<table width="200" height="7" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td></td>
 </tr>
</table>
<table width="608" height="200" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#7ED227">
 <tr>
  <td width="150" bgcolor="#F6FEFE" valign="top">
  <table width="150" border="0" cellpadding="0" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#D6FEFE">
   <?php
     $sql = mysql_query("select typename,username from tb_type order by addtime desc", $connID);
     $result = mysql_fetch_array($sql);
     if ($result){
       do{
   ?>
   <tr>
    <td bgcolor="#A6E617" height="20"><div align="center"><a href="#" rel="external nofollow" rel="external nofollow" class="a1"><?= $result['typename']?></a></div></td>
   </tr>
   <tr>
    <td bgcolor="#F2F2F2" height="12"><div align="left">發(fā)布人:
     <?= $result['username']?>
     </a></div></td>
   </tr>
   <?php
       }while($result = mysql_fetch_array($sql));
     }else{
   ?>
   <tr>
    <td bgcolor="#A6E617" height="20">暫無(wú)文章類(lèi)別</td>
   </tr>
   <?php
     }
   ?>
</table>
  </td>
  <td width="455" bgcolor="#FFFFFF" style="padding-left:30px; line-height:25px">
  請(qǐng)輸入博客類(lèi)別:<br />
      <input type="text" name="typename" size="30" id="typename" /><br /><br/>
  發(fā)布人:<br />
      <input type="text" name="username" size="30" id="username" /><br /><br/>
  <input type="button" value="保存" onclick="saveType(typename.value, username.value)" />
  </td>
 </tr>
</table>
<table width="200" height="7" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td></td>
 </tr>
</table>
<table width="608" height="70" border="0" align="center" cellpadding="0" cellspacing="0">
 <tr>
  <td background="images/bottom.gif"><div align="center">
   <DIV align="center">『博客』 版權(quán)所有 <a href="http://www.mingri***.com" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="a1">吉林省**科技有限公司</a>!  未經(jīng)授權(quán)禁止復(fù)制或建立鏡像!<BR>
     <BR>Copyright © <a href="http://www.mingri***.com" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="a1">www.mingri***.com</a> All Rights Reserved!<BR>
   </DIV>
  </div></td>
 </tr>
</table>
</body>
</html>

二. 運(yùn)行結(jié)果

PHP+Ajax實(shí)現(xiàn)的博客文章添加類(lèi)別功能示例

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲婷婷日日综合婷婷噜噜噜 | 日本特级a一片免费观看 | 曰本三级日本三级日本三级 | 日韩视频一二三 | 亚洲成人欧美 | 久久91亚洲精品久久91综合 | 国产精品自拍av | 精品国产一区二区三区成人影院 | 日日草夜夜| 日本网站一区二区三区 | 久久久久北条麻妃免费看 | 亚洲精品一区二区三区大胸 | 亚洲成人福利在线 | 国产精品免费麻豆入口 | 国产自在自线午夜精品视频在 | 欧美成人一区二区三区 | 国产小视频一区 | 全黄裸片武则天艳史 | 精品国产91一区二区三区 | 91av久久 | 在线成人免费观看www | 91精品动漫在线观看 | 久久久一区二区精品 | 一色桃子av大全在线播放 | 久久激情国产 | 久久9999久久 | 高清久久久 | 久久久久久久午夜 | 国产精品一区二区三区在线 | 国产精品免费一区二区三区都可以 | 日韩精品二区 | 久久精品.com| 亚洲第一视频 | 日本成人二区 | 国产免费观看电影网站 | 成人免费一区二区三区视频网站 | 日韩色视频 | 久久久三区| 久久久久国产成人免费精品免费 | 久久精国 | 午夜精品网站 |