欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2018年03月29日 14:23:58   作者:chengqiuming  
這篇文章主要介紹了PHP+Ajax實(shí)現(xiàn)的博客文章添加類別功能,結(jié)合實(shí)例形式分析了php+ajax實(shí)現(xiàn)的數(shù)據(jù)交互、數(shù)據(jù)庫(kù)連接、查詢等相關(guān)操作技巧,需要的朋友可以參考下

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

一. 代碼

fun.js

function saveType(typename, username){
  if(typename==''){   //判斷博客類別是否為空
    alert('請(qǐng)輸入類別名稱!');
  }else if(username==''){   //判斷用戶名是否為空
    alert('請(qǐng)輸入用戶名!');
  }else{
    var xmlObj;   //定義XMLHttpRequest對(duì)象
    var urlData = "typename="+typename+"&username="+username;    //指定要發(fā)送的數(shù)據(jù)
    if(window.ActiveXObject){   //判斷瀏覽器是否支持ActiveXObject組件,如支持則通過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ù)類型
    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('類別添加成功!');
        }else{
          alert('類別添加失??!');
        }
      }
    }
  }
}

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>添加類別</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ú)文章類別</td>
   </tr>
   <?php
     }
   ?>
</table>
  </td>
  <td width="455" bgcolor="#FFFFFF" style="padding-left:30px; line-height:25px">
  請(qǐng)輸入博客類別:<br />
  &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="typename" size="30" id="typename" /><br /><br/>
  發(fā)布人:<br />
  &nbsp;&nbsp;&nbsp;&nbsp;<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  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="a1">吉林省**科技有限公司</a>!  未經(jīng)授權(quán)禁止復(fù)制或建立鏡像!<BR>
     <BR>Copyright &copy; <a  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>添加類別</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ú)文章類別</td>
   </tr>
   <?php
     }
   ?>
</table>
  </td>
  <td width="455" bgcolor="#FFFFFF" style="padding-left:30px; line-height:25px">
  請(qǐng)輸入博客類別:<br />
  &nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="typename" size="30" id="typename" /><br /><br/>
  發(fā)布人:<br />
  &nbsp;&nbsp;&nbsp;&nbsp;<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  rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="a1">吉林省**科技有限公司</a>!  未經(jīng)授權(quán)禁止復(fù)制或建立鏡像!<BR>
     <BR>Copyright &copy; <a  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é)果

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP+ajax技巧與應(yīng)用小結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

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

相關(guān)文章

  • PHP 圖像尺寸調(diào)整代碼

    PHP 圖像尺寸調(diào)整代碼

    創(chuàng)建圖像縮略圖需要許多時(shí)間,此代碼將有助于了解縮略圖的邏輯。
    2010-05-05
  • php代碼中使用換行及(\n或\r\n和br)的應(yīng)用

    php代碼中使用換行及(\n或\r\n和br)的應(yīng)用

    瀏覽器識(shí)別不了\n或\r\n,這兩個(gè)換行符是文本換行符,文本文件有效;如果需要將結(jié)果輸出到瀏覽器或打印到顯示器,代碼中使用br;如果只是在源代碼中換行,則使用\n或\r\n,感興趣的朋友可以了解下,或許對(duì)你學(xué)習(xí)php有所幫助
    2013-02-02
  • PHP利用REFERER根居訪問來(lái)地址進(jìn)行頁(yè)面跳轉(zhuǎn)

    PHP利用REFERER根居訪問來(lái)地址進(jìn)行頁(yè)面跳轉(zhuǎn)

    這篇文章主要是根據(jù)referfer判斷來(lái)源,然后跳轉(zhuǎn)到制定頁(yè)面,以防出現(xiàn)了無(wú)法訪問頁(yè)面,用戶體驗(yàn)不好
    2013-09-09
  • php intval函數(shù)用法總結(jié)

    php intval函數(shù)用法總結(jié)

    在本篇內(nèi)容里小編給大家總結(jié)了關(guān)于php intval函數(shù)用法以及相關(guān)知識(shí)點(diǎn)總結(jié),需要的朋友們跟著學(xué)習(xí)下。
    2019-04-04
  • PHP中函數(shù)rand和mt_rand的區(qū)別比較

    PHP中函數(shù)rand和mt_rand的區(qū)別比較

    mt_rand() 比rand() 快四倍,很多老的 libc 的隨機(jī)數(shù)發(fā)生器具有一些不確定和未知的特性而且很慢。PHP 的 rand() 函數(shù)默認(rèn)使用 libc 隨機(jī)數(shù)發(fā)生器。mt_rand() 函數(shù)是非正式用來(lái)替換它的。
    2012-12-12
  • PHP mysqli事務(wù)操作常用方法分析

    PHP mysqli事務(wù)操作常用方法分析

    這篇文章主要介紹了PHP mysqli事務(wù)操作常用方法,結(jié)合實(shí)例形式分析了php操作mysqli事務(wù)的打開、提交、執(zhí)行、回退、關(guān)閉等實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2017-07-07
  • 淺析php學(xué)習(xí)的路線圖

    淺析php學(xué)習(xí)的路線圖

    一直都想走上碼農(nóng)的道路,奈何當(dāng)年沒有學(xué)好。一直與碼農(nóng)無(wú)緣?,F(xiàn)在又想做一些碼農(nóng)就下了一套某個(gè)培訓(xùn)機(jī)構(gòu)的php視頻來(lái)看。希望能走上碼農(nóng)的道路
    2013-07-07
  • 刪除html標(biāo)簽得到純文本可處理嵌套的標(biāo)簽

    刪除html標(biāo)簽得到純文本可處理嵌套的標(biāo)簽

    這篇文章主要介紹了通過刪除html標(biāo)簽得到的純文本可處理嵌套的標(biāo)簽,需要的朋友可以參考下
    2014-04-04
  • phpExcel導(dǎo)出大量數(shù)據(jù)出現(xiàn)內(nèi)存溢出錯(cuò)誤的解決方法

    phpExcel導(dǎo)出大量數(shù)據(jù)出現(xiàn)內(nèi)存溢出錯(cuò)誤的解決方法

    我們經(jīng)常會(huì)使用phpExcel導(dǎo)入或?qū)離ls文件,但是如果一次導(dǎo)出數(shù)據(jù)比較大就會(huì)出現(xiàn)內(nèi)存溢出錯(cuò)誤,下面我來(lái)總結(jié)解決辦法
    2013-02-02
  • PHP實(shí)現(xiàn)貨幣換算的方法

    PHP實(shí)現(xiàn)貨幣換算的方法

    這篇文章主要介紹了PHP實(shí)現(xiàn)貨幣換算的方法,以實(shí)例形式較為詳細(xì)的講述了貨幣轉(zhuǎn)換的實(shí)現(xiàn)方法,并舉英鎊轉(zhuǎn)換美元為例講述具體用法,需要的朋友可以參考下
    2014-11-11

最新評(píng)論