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.

    评论

报告相同问题?