How ajax traverses this array structure and outputs it to html

recently learned that ajax only html and css knowledge of the rookie is not to understand this thing, this is not like the big guys to ask for advice!

the data structure of the request is as follows: $aja () mode
{
"list": [{"id": 1, "name": "Xiaobai"}, {"id": 2, "name": "Xiao Hei"}, {"id": 3, "name": "Xiao Hong"}]
}

request code:

 $.ajax({
      url:"data.html",
      type:"get",
      dataType:"html",
      success: function(list){
              alert("");
            },
            error:function(){
              alert("");
            }
       })

I want to output to html structure as follows:

  • No.: 1 name: Xiaobai

  • No.: 2 name: Xiao Hei

  • No.: 3 name: Xiao Hong
  • ask the bosses for help?

    Jul.30,2021

    this is js's problem

    var data = {
    "list": [{"id": 1,"name": ""},{"id": 2,"name": ""},{"id": 3,"name": ""}]
    }
    
    var html = ''
    html = data.list.map(function(item){
        return "<li>:"+item.id+" :"+ item.name +"</li>"
    }).join('')

    var html='';
    $.ajax ({

    )
      url:"data.html",
      type:"get",
      dataType:"html",
      success: function(list){
          for(list in item){
          html+='<li>:'+item['id']+' :'+item['name']+'</li>
            },
            error:function(){
              alert("");
            }
       })
       
       html
        $('-sharpresult').html(Html);
        
        
        ide
       
       

    the answer given on the first floor is very perfect. Higher-order function map traversal, but one thing is that higher-order function traversal cannot be stopped once it starts, so it depends on the needs of the landlord. If you only need a structure, that's no problem.


    is there something wrong with my method? why is it more and more each time, rather than the additional effect?

    var refresh_open = true;
    var page=1;//
    var mid=1;//mid:123        
    var limit=20;//10,20,30 
    var html='' ;
    function ajax_dat(){
      if(refresh_open){
        $.ajax({
            url:maccms.path+"/index.php/ajax/data.html",
            type:"POST",
            dataType:"json",
            data: 'mid='+mid+'&page='+page+'&limit='+limit+'',//url
            success:function(data){
                if(data){
                    var vod=data['list']
                    for (var i = 0; i < vod.length; iPP) {
                      html +='<dd class="odd">';
                      html +='<a href="'+vod[i].detail_link+'" class="hx_title">'+vod[i].vod_name+'</a></dd>';
                     }
                      var vod_list=$('-sharpvod_list');
                      vod_list.append(html);
                      page +=1
                      setTimeout(function(){
                         refresh_open = true;
                       },100);
                    }else{
                      alert("")  
                   };
               },
            error:function(){
                      alert("");
                    }
            })
        }
    }
    
    Menu