zoukankan      html  css  js  c++  java
  • ajax

    <script type="text/javascript">
    $(function(){
        initindexItem();
    });
    function initindexItem(){
        alert("ffffff");
    
        
        
        window.onload = function() {
            //得到核心对象
            var xmlHttp = new XMLHttpRequest();
            //打开连接
            xmlHttp.open("post", "register.action", true);
            //发送
            xmlHttp.send(null);
            //添加监听
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {//响应完成
                    if (xmlHttp.status == 200) {//判断响应是否成功
                        //执行服务器发送过来的json字符串 得到 js的对象
    
                        alert(xmlHttp.responseText);
                    
    
                        
                    }
                }
    
            };
        };

     下面这个是应用到项目中的:

    <script type="text/javascript">
    $(function(){
        initindexItem();
    });
    function initindexItem(){
        $.ajax({
            type:'POST',
            url:'register.action',
            dataType:'json',
            contentType:'application/json;charset=UTF-8',
            success:function(data){
                console.log(data);
                var html = ''
                for (var i = 0; i < data.length; i++) {
                    html +='<tr>'
                    html +='<td>'+data[i].id+'</td>'
                    html +='<td>'+data[i].number+'</td>'
                    html +='<td>'+data[i].fangshi+'</td>'
                    html +='<td>'+data[i].value+'</td>'
                    html +='<td>'+data[i].shijian+'</td>'
                    html +='</tr>'
                }
                $('#tab').append(html)
            }
        });
    
    };
        
    </script>
  • 相关阅读:
    ASP.NET Core学习——7
    ASP.NET Core学习——6
    ASP.NET Core学习——6
    ASP.NET Core学习——5
    ASP.NET Core学习——4
    平衡的括号(名字怪怪的~)
    找复合单词
    卡片游戏
    Ducci 序列
    卡片游戏O(∩_∩)O
  • 原文地址:https://www.cnblogs.com/suiyisuixing/p/7709383.html
Copyright © 2011-2022 走看看