最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2017年12月22日 09:04:59   作者:living_ren  
下面小編就為大家分享一篇ajax結(jié)合mysql數(shù)據(jù)庫和smarty實現(xiàn)局部數(shù)據(jù)狀態(tài)的刷新方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

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

1.主程序:01.php導(dǎo)入smarty和mysql類,取得數(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>用戶權(quán)限展示表</title>
</head>
<body>
    <table align="center" border="1" width="500">
      <center><h2>用戶權(quán)限表</h2></center>
      <tr>
        <th>uid</th><th>用戶名</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對象
          var xhr=new XMLHttpRequest();
          //打開一個鏈接
          xhr.open('get','02.php?is_lock='+lock+"&uid="+uid);
          //發(fā)送ajax請求
          xhr.send(null);
          //設(shè)置回調(diào)、監(jiān)聽函數(shù)
          xhr.onreadystatechange=function(){
            //如果ajax狀態(tài)碼響應(yīng)正常且網(wǎng)絡(luò)正常,獲取響應(yīng)文本
            if(xhr.readyState==4&&xhr.status==200){
              if(xhr.responseText){
                window.location.reload();
              }else{
                alert("切換狀態(tài)失敗!");
              }
            }
          }
        }
    </script>
</html>

3.ajax響應(yīng)腳本,接收ajax通過get方式傳遞過來的數(shù)據(jù)更改數(shù)據(jù)庫內(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ù)庫和smarty實現(xiàn)局部數(shù)據(jù)狀態(tài)的刷新方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

海南省| 岐山县| 乡城县| 南城县| 高陵县| 锡林郭勒盟| 繁昌县| 沐川县| 桑植县| 大埔县| 泰兴市| 行唐县| 台江县| 沂水县| 东光县| 福海县| 连平县| 怀仁县| 永德县| 宝丰县| 朝阳县| 阜平县| 山阳县| 慈利县| 瑞昌市| 寻乌县| 托克逊县| 东乌| 绥德县| 靖州| 仲巴县| 桓台县| 蒲城县| 磐安县| 南投县| 梁平县| 武强县| 桂林市| 白水县| 太保市| 宁河县|