码迷,mamicode.com
首页 > Web开发 > 详细

ajax实例

时间:2017-08-14 23:42:33      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:ajax   html   node   script   type   span   pre   load   class   

<script>

 function ajaxFn(url, HTMLNode) {
    $.ajax({
         type: GET,
         url: url,
         data: {},
         dataType: json,
         success: function(result) {
             var html = "";
             for(var i = 0; i < 5; i++) {
                 console.log(result[i].name);
                 html += (<li>+result[i].name+</li>)
             }
             $(HTMLNode).html(html)
         },
         error: function() {
             console.log("数据请求失败");
         }
     })
}
 window.onload = function() {
     ajaxFn(/ganController/xuanhuan.action, "#init ul");
 }

</script>

后端要把集合转换成json格式。

在这里感谢明月大佬(qq185617705)不厌其烦指教。 

ajax实例

标签:ajax   html   node   script   type   span   pre   load   class   

原文地址:http://www.cnblogs.com/suiyisuixing/p/7360627.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!