jQuery使用load()或ajax()在aspx页面上的IE9(兼容模式)下无法加载页面片段 [英] Jquery loading page fragment using load() or ajax() not working on IE9 (compatability mode) on an aspx page

查看:149
本文介绍了jQuery使用load()或ajax()在aspx页面上的IE9(兼容模式)下无法加载页面片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在aspx页面上执行load()ajax()时遇到问题.我正在尝试仅加载一个片段,它在IE9(常规),FF和Chrome中可以正常工作.

当我切换到兼容模式时,找不到片段. (返回null).

我使用的代码用于一个链接,单击该链接将调用SAME页面,但仅包含不同的数据. (使用另一个查询字符串值调用同一页面)

以下是加载数据:

$("#gvHistory a").live("click", function () {
            var link = $(this);
            var linkHref = link.attr("href");
            if (linkHref.indexOf("detail") != -1) {
                dynamicDiv.hide(); //hide div then use load function
                dynamicDiv.load(linkHref + " #divDetails",
            {},
            function () {
                dynamicDiv.fadeIn("slow");
            });
                return false;
            }
        });

这没有做任何事情,响应已经完成,并且我可以看到整个页面的HTML,但是它不会加载它.正因为如此,我尝试使用ajax()并遇到了相同的问题. /p>

代码如下:

function LoadProductSpecHistory(link,divToUse) {
    $panel = $('#' + divToUse);
    //Link variable contains the page and the querystring value
    $.ajax({
        url: "/ProductDevelopment/ProductSpecs/" + link,
        type: "GET",
        dataType: "html",
        async: false,
        data: {},
        success: function (obj, status, xhr) {
            // obj will contain the complete contents of the page requested
            // use jquery to extract just the html inside the tag
            $content = $('#divDetails', obj).html(); //THIS IS WHERE IS WON't WORK!!!!!
            // then update the div contents with this and show it
            $panel.html($content);
            $panel.show();
        }
    });
}

这会得到响应,但是当我执行$content = $('#divDetails', obj).html(); 时,它将在兼容模式(旧版IE)上返回null,但在正常模式下它将返回我需要的HTML.

为什么会发生这种情况?我需要进行任何更改才能使其在较旧的IE(或兼容模式)上运行.

解决方案

已修复 哇,简单的标签可以做什么...

所以我解决了这个问题,问题是有一个封闭的地方,没有任何开放的div.很难找到,因为这是在MASTER PAGE中.看到了Visual Studio出现的弯曲线条,所以它告诉了我.显然,较旧的IE版本对xml布局(或xhtml)非常严格.

因此,请确保所有打开的标签都具有匹配的关闭标签!...

使用load()方法工作.

非常感谢您的答复.

I am having an issue when trying to do load() and ajax() on an aspx page. I am trying to load just a fragment and it works fine in IE9 (Normal), FF and Chrome.

When I switch to compatibility mode it doesn't find the fragment. (returns null).

My code used is used on a link that when clicked will invoke the SAME page but with just a different data. (call the same page withe another querystring value)

Here's the load data:

$("#gvHistory a").live("click", function () {
            var link = $(this);
            var linkHref = link.attr("href");
            if (linkHref.indexOf("detail") != -1) {
                dynamicDiv.hide(); //hide div then use load function
                dynamicDiv.load(linkHref + " #divDetails",
            {},
            function () {
                dynamicDiv.fadeIn("slow");
            });
                return false;
            }
        });

This does not do anything, the response is complete, and I can see the whole page HTML but it won't load it...because of this I tried using ajax() and came up with the same problem.

Here's the code:

function LoadProductSpecHistory(link,divToUse) {
    $panel = $('#' + divToUse);
    //Link variable contains the page and the querystring value
    $.ajax({
        url: "/ProductDevelopment/ProductSpecs/" + link,
        type: "GET",
        dataType: "html",
        async: false,
        data: {},
        success: function (obj, status, xhr) {
            // obj will contain the complete contents of the page requested
            // use jquery to extract just the html inside the tag
            $content = $('#divDetails', obj).html(); //THIS IS WHERE IS WON't WORK!!!!!
            // then update the div contents with this and show it
            $panel.html($content);
            $panel.show();
        }
    });
}

This gets the response, but when I do the $content = $('#divDetails', obj).html(); It returns null on compatibility mode (older IE) but on normal mode it returns the HTML I need.

Any reason why this might be happening? Any changes that I would need to make it work on older IE (or compatibility mode).

解决方案

FIXED Wow, what a simple tag can do...

So I fixed this and the problem was that there was a closed with no opening div anywhere. It was a pain to find since this was in the MASTER PAGE..saw the squiggly line that visual studio brings up and so it told me..took it out and checked again and it worked. Apprarently older IE versions are very strict with the xml layout (or xhtml).

So, MAKE sure all open tags have a matching closing tag!...

Worked using the load() method.

Thanks all for the replies.

这篇关于jQuery使用load()或ajax()在aspx页面上的IE9(兼容模式)下无法加载页面片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆