佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > ajax結(jié)合mysql數(shù)據(jù)庫(kù)和smarty實(shí)現(xiàn)局部數(shù)據(jù)狀態(tài)的刷新方法

ajax結(jié)合mysql數(shù)據(jù)庫(kù)和smarty實(shí)現(xiàn)局部數(shù)據(jù)狀態(tài)的刷新方法

熱門(mén)標(biāo)簽:團(tuán)購(gòu)網(wǎng)站 電子圍欄 服務(wù)器配置 阿里云 銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 Linux服務(wù)器 科大訊飛語(yǔ)音識(shí)別系統(tǒng)

效果狀態(tài):通過(guò)點(diǎn)擊鎖定狀態(tài)實(shí)現(xiàn)狀態(tài)鎖定與不鎖定之間的切換

1.主程序:01.php導(dǎo)入smarty和mysql類(lèi),取得數(shù)據(jù)導(dǎo)入列表模板

?php
  include './include/Mysql.class.php';
  include './libs/Smarty.class.php';
  $db=new Mysql;
  $smarty=new Smarty;
  $lists=$db->getALL('users');
  $smarty->assign('lists',$lists);
  $smarty->display('list.html');
?>

2.列表模板采用smarty遍歷模板數(shù)據(jù)并顯示,其中調(diào)用ajax改變鎖定狀態(tài)

!DOCTYPE html>
html>
head>
  meta charset=utf-8>
  title>用戶(hù)權(quán)限展示表/title>
/head>
body>
    table align="center" border="1" width="500">
      center>h2>用戶(hù)權(quán)限表/h2>/center>
      tr>
        th>uid/th>th>用戶(hù)名/th>th>密碼/th>th>鎖定狀態(tài)/th>th>角色/th>
      /tr>  
      {foreach $lists as $list}
        tr align="center">
          td>{$list.uid}/td>
          td>{$list.username}/td>
          td>{$list.password}/td>
          {if $list.is_lock==1}
            td>a href="javascript:lock(0,{$list.uid});" rel="external nofollow" >鎖定/a>/td>
            {else}
            td>a href="javascript:lock(1,{$list.uid})" rel="external nofollow" ;>取消鎖定/a>/td>  
          {/if}    
          {if $list.role==1}
              td>管理員/td>
          {else}
              td>編輯者/td>    
          {/if}
        /tr>    
      {/foreach}  
    /table>  
/body>
    script type="text/javascript">
      function lock(lock,uid){
          //創(chuàng)建ajax對(duì)象
          var xhr=new XMLHttpRequest();
          //打開(kāi)一個(gè)鏈接
          xhr.open('get','02.php?is_lock='+lock+"uid="+uid);
          //發(fā)送ajax請(qǐng)求
          xhr.send(null);
          //設(shè)置回調(diào)、監(jiān)聽(tīng)函數(shù)
          xhr.onreadystatechange=function(){
            //如果ajax狀態(tài)碼響應(yīng)正常且網(wǎng)絡(luò)正常,獲取響應(yīng)文本
            if(xhr.readyState==4xhr.status==200){
              if(xhr.responseText){
                window.location.reload();
              }else{
                alert("切換狀態(tài)失??!");
              }
            }
          }
        }
    /script>
/html>

3.ajax響應(yīng)腳本,接收ajax通過(guò)get方式傳遞過(guò)來(lái)的數(shù)據(jù)更改數(shù)據(jù)庫(kù)內(nèi)容并響應(yīng)文本傳回js腳本

?php
  include './include/Mysql.class.php';
  $lock=$_GET['is_lock'];
  $uid=$_GET['uid'];
  $db=new Mysql;
  $result=$db->update('users',"is_lock=$lock","uid=$uid");
  if($result){
    echo true;
  }else{
    echo false;
  }
?>

以上這篇ajax結(jié)合mysql數(shù)據(jù)庫(kù)和smarty實(shí)現(xiàn)局部數(shù)據(jù)狀態(tài)的刷新方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

您可能感興趣的文章:
  • Ajax+smarty技術(shù)實(shí)現(xiàn)無(wú)刷新分頁(yè)
  • php+ajax實(shí)現(xiàn)無(wú)刷新動(dòng)態(tài)加載數(shù)據(jù)技術(shù)
  • php+mysql結(jié)合Ajax實(shí)現(xiàn)點(diǎn)贊功能完整實(shí)例

標(biāo)簽:蚌埠 衢州 萍鄉(xiāng) 棗莊 江蘇 廣元 大理 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ajax結(jié)合mysql數(shù)據(jù)庫(kù)和smarty實(shí)現(xiàn)局部數(shù)據(jù)狀態(tài)的刷新方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266
    福清市| 习水县| 汽车| 泗阳县| 台中县| 大港区| 清水县| 公安县| 南平市| 沅陵县| 从化市| 巴林右旗| 黎城县| 贺州市| 黄浦区| 白朗县| 怀化市| 泸西县| 綦江县| 新津县| 疏附县| 油尖旺区| 靖安县| 武川县| 广丰县| 正定县| 论坛| 车险| 综艺| 贵南县| 赣榆县| 宁阳县| 商丘市| 连平县| 南通市| 甘谷县| 思南县| 孙吴县| 马边| 鲜城| 仁化县|