本文介绍了jQuery追加在Internet Explorer中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回JSON数据的jquery函数:此功能在Google Chrome浏览器中有效,但在Internet Explorer(v11)中无效.

I have a jquery function that returns JSON data:This function works in Google Chrome, but not in Internet Explorer (v11).

$(document).ready(function () {

    $.ajax({
        url: "/../Projects/1/_vti_bin/ListData.svc/Prosjectlist?$select=ID,Tittel,Project_typeValue,Project_heading&$filter=(Project_typeValue%20eq%20%27Type1%27)",
        method: "GET",
        dataType: "JSON",
        headers: { "accept": "application/json; odata=verbose" },
        success: function (data) {
            $('#projectRow').empty();

            $.each(data.d.results, function (index, item) {
                var itemExist = false;
                $.each($('.projectRow').find('h1'), function (index1, item1) {
                    if (item1.innerHTML == item.Project_heading) {
                        itemExist = true;
                        $(item1).parent().append("<h3><a id='" + item.ID + "' class='projectLink' href='#'>" + item.Title + "</a></h3>");

                    }
                });
                if (itemExist == false)
                    $('.projectRow').append("<div class='projectHeadingDiv left'><li><h1>" + item.Project_heading + "</h1><h3><a id='" + item.ID + "' class='projectLink' href='#'>" + item.Title + "</a></h3></div></li></div>");

            });
        },
        error: function (error) {
            alert(JSON.stringify(error));
        }
    });

我正在使用jQuery 1.5.2(如果使用任何新版本,SharePoint 2010将会变得模糊).我一直在查看IE11中的调试器,并且数据在那里,只是不会附加到我的div中.似乎添加可能是罪魁祸首,因为如果我将.append()替换为.html(),则可以看到$each-loop中的最后一项.例如:

I am using jQuery 1.5.2 (Sharepoint 2010 gets fuzzy if I use anything newer). I have been looking at the debugger in IE11 and the data is there, it just won't append to my div. It seems that append might be the culprit, because if I replace .append() with .html() I can see the last item in the $each-loop. E.g:

$(item1).parent().html("<h3><a id='" + item.ID + "' class='projectLink' href='#'>" + item.Title + "</a></h3>");

有人知道为什么.append可以在Chrome而不是IE中运行吗?控制台不提供任何错误消息,因此也没有任何提示.但是,如果我要在IE开发工具中将文档模式"从8(默认)更改为9或更高版本,它似乎可以正常工作.

Does anyone know why .append works in Chrome and not IE? The console doesn't give any error messages, and therefore no clues. However if I were to change "Document Mode" in IE dev tools from 8 (default) to 9 or higher, it appears to work as it should.

任何帮助将不胜感激.

Any help is greatly appreciated.

推荐答案

您有两个不匹配的结束标记</div></li>.修复HTML,它应该可以工作:

You have two unmatched closing tags </div></li>. Fix HTML and it should work:

<div class='projectHeadingDiv left'><li><h1>" + item.Project_heading + "</h1><h3><a id='" + item.ID + "' class='projectLink' href='#'>" + item.Title + "</a></h3></div>

Chrome和Firefox更适合那些粗心的开发人员.但是IE对这种错误(我认为确实不错)更敏感.

Chrome and Firefox are more forgiving to such careless of developers. But IE is more sensitive to this kind of errors (which I actually think good).

这篇关于jQuery追加在Internet Explorer中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 10:55