jQuery .html() function doesnt work in IE 11

故事扮演 提交于 2019-12-10 14:15:40

问题


In my .net MVC3 web application i have an ajax call that returns some html code. I pass this html into a div like so:

    $.ajax({
            url: 'controller/action',
            data: {id: id,},
            type: 'GET',
            async: false,
            success: function (data) {
                $("#container").html(data);

            },
        });

This works fine in all browsers except ie 11. What happens is that the html doesnt render in #container div unless i click somewhere on the page.

How can i get the html to render without clicking anywhere in ie11?

thanks


回答1:


A likely cause for this is that there is some small piece of syntax in the HTML that is returned by ajax that IE is not happy with. In my case it was caused by having an HTML comment inside a <script> tag. IE fell over but other browsers were fine.

I suggest removing everything from the HTML returned by the ajax call except one line such as 'TEST'. If that works then you know it isn't a JQuery / Javascript issue. You can then add back lines into the returned HTML until you find the line that IE isn't happy with.




回答2:


 $.ajax({
            url: 'controller/action',
            data: {id: id,},
            type: 'GET',
            async: false,
            success: function (data) {
$("#container").empty().append(data);


            },
        });

Use append instead of html to avoid those issues. empty() is used to clear intially before append.



来源:https://stackoverflow.com/questions/29362015/jquery-html-function-doesnt-work-in-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!