• ajax 加载不同数据


    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script>
    
    function fn1 (data)
    {
        var oul1 = document.getElementById('ul1');
        var html = '';
        for(var i = 0; i < data.length; i++)
        {
            html += '<li>'+ data[i] +'</li>'
        }
        
        oul1.innerHTML = html;
    }
    
    function fn2 (data)
    {
        var oul2 = document.getElementById('ul2');
        var html = '';
        for(var i = 0; i < data.length; i++)
        {
            html += '<li>'+ data[i] +'</li>'
        }
        
        oul2.innerHTML = html;
    }
    
    function fn3 (data)
    {
        var oul3 = document.getElementById('ul3');
        var html = '';
        for(var i = 0; i < data.length; i++)
        {
            html += '<li>'+ data[i] +'</li>'
        }
        
        oul3.innerHTML = html;
    }
    
    window.onload = function ()
    {
        var obtn1 = document.getElementById('btn1');
        var oul1 = document.getElementById('ul1');
        
        obtn1.onclick = function ()
        {
            var oscript = document.createElement('script');
            oscript.src = 'getData.php?callback=fn1';
            document.body.appendChild(oscript);
        }
        
        
        
        var obtn2 = document.getElementById('btn2');
        var oul2 = document.getElementById('ul2');
        
        obtn2.onclick = function ()
        {
            var oscript = document.createElement('script');
            oscript.src = 'getData.php?t=str&callback=fn2';
            document.body.appendChild(oscript);
        }
        
        var obtn3 = document.getElementById('btn3');
        var oul3 = document.getElementById('ul3');
        
        obtn3.onclick = function ()
        {
            var oscript = document.createElement('script');
            oscript.src = 'getData.php?t=str&callback=fn3';
            document.body.appendChild(oscript);
        }
    }
    </script>
    </head>
    
    <body>
        <input type="button" id="btn1" value="加载数字">
        <ul id="ul1"></ul>
        <input type="button" id="btn2" value="加载字母" />
        <ul id="ul2"></ul>
        <input type="button" id="btn3" value="加载字母" />
        <ul id="ul3"></ul>
        
    </body>
    </html>
    <?php
    $t = isset($_GET['t']) ? $_GET['t'] : 'num';
    $callback = isset($_GET['callback']) ? $_GET['callback'] : 'fn1';
    
    $arr1 = array('111111','22222222','33333333','4444444','555555555555555555555');
    $arr2 = array('aaaaaaaaaaaa','bbbbbbbb','cccccccccccc','ddddddddd','eeeeeeeeeeee');
    
    if ($t == 'num') {
        $data = json_encode($arr1);
    } else {
        $data = json_encode($arr2);
    }
    
    echo $callback.'('.$data.');';
  • 相关阅读:
    设置root密码
    切分和组合图片(一)
    android 游戏开发libgdx(一)
    用SharePoint.OpenDocuments打开的文档如何控制它的ActiveWindow.View.ShowXMLMarkup(转)
    sp_helptext 命令
    CMMI 配置管理 简介(转)
    文本框中只能输入字符的正则表达式.
    基于CMM和CMMI的配置管理(转)
    正则表达式详述(转)
    选中多个CheckBox赋给文本框.
  • 原文地址:https://www.cnblogs.com/mayufo/p/4299646.html
Copyright © 2020-2023  润新知