AJAX数据交互的简单实现

时间:2026-02-16 15:38:43

1、<body>

<input type="button" value="点击" id="btn1">

</body>

2、data.json:

[

  {"name":"21"},

  {"name":"22"},

  {"name":"23"},

  {"name":"24"},

  {"name":"25"}

]

3、<script src="js/jquery-2.1.1.min.js"></script>

<script type="text/javascript">

$('#btn1').click(function(){

    $.ajax({

        url:'data.json',

        dataType:'json',

        type:'POST',

        success:function(res){

            //console.log(res);

            $.each(res,function(i,n){

                var oLi='<li>'+n["name"]+'</li>';

                alert(oLi);

                document.write(oLi)

            })

        }

    })

})

© 2026 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com