• 笔记:2016-06-12


    ajax

    var url = 'open.php?username='+ encodeURIComponet(username)+'&password='+password;

    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
        <book>
            <name>三国演义</name>
            <category>文学</category>
            <desc>描述</desc>
        </book>   
        <book>
            <name>水浒传</name>
            <category>文学</category>
            <desc>草寇or英雄豪杰</desc>
        </book>   
        <book>
            <name>西游记</name>
            <category>文学</category>
            <desc>妖魔鬼怪牛鬼蛇神什么都有</desc>
        </book>   
        <book>
            <name>红楼梦</name>
            <category>文学</category>
            <desc>宝哥哥与林妹妹的爱情史</desc>
        </book>   
    </bookstore>

    <script type="text/javascript">
        window.onload = function(){
            var btn = document.getElementById('btn');
            btn.onclick = function(){
                showBookInfo();
            }
            function showBookInfo(){
                document.getElementById('bookInfo').innerHTML = '';
                var xhr = null;
                if(window.XMLHttpRequest){
                    xhr = new XMLHttpRequest();
                }else{
                    xhr = new ActiveXObject('Microsoft.XMLHTTP');
                }
                console.log('第一步'+xhr.readyState);
                xhr.open('get','./data.xml');
                console.log('第二步'+xhr.readyState);
                xhr.send(null);
                xhr.onreadystatechange = function(){
                    if(xhr.readyState == 4 && xhr.status == 200){
                        var data = xhr.responseXML;
                       
                        var bs = data.getElementsByTagName('bookstore')[0];
                        console.log(bs);
                        var books = bs.getElementsByTagName('book');
                        var tag = '';
                        for(var i=0;i<books.length;i++){
                            var book = books[i];
                            var name = book.getElementsByTagName('name')[0];
                            var category = book.getElementsByTagName('category')[0];
                            var desc = book.getElementsByTagName('desc')[0];
                            tag += '<tr><td>'+getNodeText(name)+'</td><td>'+getNodeText(category)+'</td><td>'+getNodeText(desc)+'</td></tr>';
                        }
                        var tbody = document.createElement('tbody');
                        tbody.innerHTML = tag;
                        document.getElementById('bookInfo').appendChild(tbody);
                    }
                }
               
           
            }
       
        }
        //获取文本节点内容
        function getNodeText(node){
            if(window.ActiveXObject){//IE
                return node.text;
            }else{//标准浏览器
                if(node.nodeType == 1){
                    return node.textContent;
                }
            }
        }
    </script>

    {
        "total":"4",
        "data":[
            {
                "name":"三国演义",
                "category":"文学",
                "desc":"一个军阀混战的年代"
            },{
                "name":"水浒传",
                "category":"文学",
                "desc":"草寇or英雄好汉"
            },{
                "name":"西游记",
                "category":"文学",
                "desc":"妖魔鬼怪牛鬼蛇神什么都有"
            },{
                "name":"红楼梦",
                "category":"文学",
                "desc":"一个封建王朝的缩影"
            }
        ],
        "obj":{"adf":"adf"}
    }

    <script type="text/javascript">
        window.onload = function(){
            var btn = document.getElementById('btn');
            btn.onclick = function(){
                showBookInfo();
            }
            function showBookInfo(){
                var xhr = null;
                if(window.XMLHttpRequest){
                    xhr = new XMLHttpRequest();
                }else{
                    xhr = new ActiveXObject('Microsoft.XMLHTTP');
                }
                xhr.open('get','./data.json');
                xhr.onreadystatechange = function(){
                    if(xhr.readyState == 4 && xhr.status == 200){
                        var data = JSON.parse(xhr.responseText);
                        console.log(data);
                        var total = data.total;
                        var list = data.data;
                        var tag = '';
                        for(var i=0;i<total;i++){
                            var book = list[i];
                            tag += '<tr><td>'+book.name+'</td><td>'+book.category+'</td><td>'+book.desc+'</td></tr>';
                        }
                        var tbody = document.createElement('tbody');
                        tbody.innerHTML = tag;
                        document.getElementById('bookInfo').appendChild(tbody);
                    }
                }
                xhr.send(null);
            }
       
        }

    </script>

    //JSON.stringify(data);

    image

    image

    eval传人js代码获取东西 危险

    image

      get的缓存问题

    image

    时间戳

    image

    $是对象

    image

    image

    函数本身就是一个对象

    image

    jsonp

    image

    image

    image

    image

    image

    image

    image

    DAO ODM

    WebKit私有的属性“-webkit-overflow-scrolling: touch”(允许独立的滚动区域和触摸回弹)

  • 相关阅读:
    51Nod 1085 背包问题 (01背包)
    Hdu2602 Bone Collector (01背包)
    Hdu1241 Oil Deposits (DFS)
    问题 1462: [蓝桥杯][基础练习VIP]Huffuman树
    结果填空:最强团队
    算法提高 排列数 (全排列)
    和 (DFS)
    洛谷P1605 迷宫 (DFS)
    Poj1979 Red and Black (DFS)
    Poj2386 Lake Counting (DFS)
  • 原文地址:https://www.cnblogs.com/binperson/p/5577165.html
Copyright © 2020-2023  润新知