AJAX数据交互的简单实现

2025-04-21 00:52:49

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.mi艘绒庳焰n.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) }) } })})

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢