LayUI & JQuery(Ajax) & PHP 練習 ~ 06_layui顏色&圖示&動畫

LayUI & JQuery(Ajax) & PHP 練習 ~ 06_layui顏色&圖示&動畫

LayUI & JQuery(Ajax) & PHP 練習 ~ 06_layui顏色&圖示&動畫


GITHUB: https://github.com/jash-git/layui-jquery-php-example/tree/main/06

相關教學文件: 教學PDF/03.pdf

index.html

<!DOCTYPE html>
<html>
    <head>
      <meta charset="utf-8">
      <link rel="stylesheet" href="layui/css/layui.css"><!-- layui css 文件 -->
        <style><!-- class css 高度設定-->
            div {
                height: 50px;
            }
            .layui-icon {
                font-size : 50px;
                color : #666;
            }
        </style>      
    </head>
    
    <body> <!-- 顏色&圖示&動畫 -->

		<div class="layui-bg-red">Layui</div>
		<div class="layui-bg-orange">Layui</div>
		<div class="layui-bg-blue">Layui</div>
		<div class="layui-bg-cyan">Layui</div>

		<div>
			<i class="layui-icon layui-icon-rmb"></i>
			<i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>
		</div>
        
        <!-- body 末尾放置所有JS -->
        <script src="./js/jquery-3.7.1.js"></script>
        <script src="layui/layui.js"></script>    
        <script>        
            $.ajax({            
              url: './index_api.php',
              type: 'Get',                          
                  beforeSend: function(){
              },
              
              success: function(data) {
                var StrMsg='';
                for (var i = 0; i < data.length; i++) {
                   StrMsg+=data[i].state + ' - ' + data[i].times+'\n';
                   console.log(data[i].state + ' - ' + data[i].times);
                }
                
                // JS彈出視窗顯示資料- alert(StrMsg);
                //https://www.layuiweb.com/doc/index.htm ~ layer msg 顯示資料,藉此判斷可以使用layer
                layui.use(['layer', 'form'], function(){
                  var layer = layui.layer
                  ,form = layui.form;
                  
                  layer.msg(StrMsg);
                });
                
              },
              
              error: function() {
              },
              
              complete: function() {

              }              
            });            
        </script>
    </body>
</html>


index_api.php

<?php
    date_default_timezone_set("Asia/Taipei");
    header('Content-Type: application/json; charset=utf-8');
    
    $myfile = fopen("log.txt", "a");
    $txt = date("Y-m-d H:i:s");
    fwrite($myfile, $txt."\n");
    
    $data = array();
    $objectBuf01 = new stdClass();
    $objectBuf01->state = "success";
    $objectBuf01->times = $txt;
    $data[] = $objectBuf01;

    // Encode the array to JSON
    $Strjson = json_encode($data);
    echo $Strjson;    
?>

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *