weixin_33743703 2018-08-01 12:18 采纳率: 0%
浏览 32

不更新模态主体

I have an empty modal on my page and I'm performing an ajax call as below (simplified for reading)

function returnIt(x)
{
    $.ajax({
    type:"POST",
    url:"link",
    data:{id:"123"},
    success: function(data)
        {
        data=JSON.parse(data);
        var content=document.getElementById("returnItModalBody").innerHTML;
        for(var i=0;i<data.length;i++)
            {
            if(data[i]["nick"]==1)
               content+="<p>"+data[i]["upd"]+"</p>";
            else
               content+="<p>"+data[i]["upd"]+"</p>";
            }
        alert(content);
        $("#returnItModal").modal('show');
        }
     });
}

When I tell the script to alert with content it shows it should show in modal. When modal opens, there is nothing in its body.

What am I missing here?

Thanks

  • 写回答

1条回答 默认 最新

  • weixin_33717117 2018-08-01 12:22
    关注
    var content=document.getElementById("returnItModalBody").innerHTML;
    

    That copies the value of innerHTML (a string) to content.

    content+="<p>"+data[i]["upd"]+"</p>";
    

    Then you assign a new string to content

    alert(content)
    

    Then you look at the string in content


    You never change innerHTML.

    If you want to change innerHTML then you have to assign a new value to it.

    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程