问题
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).
回答1:
Try this one;
$panel.html( $(obj).find('#divDetails').html() ).show();
回答2:
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.
来源:https://stackoverflow.com/questions/8565866/jquery-loading-page-fragment-using-load-or-ajax-not-working-on-ie9-compatab