bug^君 2012-12-07 14:42 采纳率: 25%
浏览 95

使用ajax填充HTML li

I currently have a list of items which should be partly filled by an AJAX call. What I have:

<li>Hello, username</li>

The AJAX call pulls the username from a database. So how do you append that pulled information to display it next to "Hello" since anything in the li tags is straight text?

The AJAX:

ajax({
    type: "GET"
    url: '../info
    success: function (data){
        if (data != ''){
            var user = info.username;
       }
    } 
})

How would the variable user be put in to the list item tag? can you do something like

<li>Hello, "$user"</li>
  • 写回答

3条回答 默认 最新

  • weixin_33693070 2012-12-07 14:51
    关注

    If you could have your items formatted like <li>Hello, <span id = "username">username</span>, it will make your life easier.

    Then you could do something like this:

    if (data != ''){
      var user = info.username;
      $('#username').html(user);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊