开发者

jQuery Load Callback in IE7

开发者 https://www.devze.com 2023-04-11 05:19 出处:网络
I have a problem with IE7 and the Callback of jQuery Load. All browsers exept IE7 fire the Callback of my Load function correctly. Just can\'t figure out a solution for that.

I have a problem with IE7 and the Callback of jQuery Load. All browsers exept IE7 fire the Callback of my Load function correctly. Just can't figure out a solution for that.

$('#cd_vk_cinemascreen').load('/index.php?id=19 #cd_content', function() {
 $('#cd_vk_cinemascreen #cd_content').attr('class', 'cm_contentWrapper');
 $('#cd_vk_cinemascreen #cd_cont开发者_开发百科ent').attr('id', 'nothing');
});

Thanks for any help.


I had this problem recently; I believe (but am not certain) it is a race condition.

When using jQuery .load with document fragments ('/index.php?id=19 #cd_content' in your case), the entire document is acquired using AJAX. It seems that at that point, the callback is launched at the same time that the AJAX-loaded document is parsed, the desired selector block is extracted and parsed out, and the ID is added to your own document.

But by the time that block is parsed out and added to your document, the callback has already started running. That callback has done nothing, of course, because at the time it is run the element it is selecting hasn't been inserted yet.

My solution was to avoid the problem: I trimmed down the AJAX-loaded document so that I didn't need to load a fragment, thus avoiding the race condition.


This is how I would do it:

$( cinemascr ).load( '/index.php?id=19 #cd_content', function () {
    $( '#cd_content', cinemascr ).
        addClass( 'cm_contentWrapper' ).
        [0].id = 'nothing';
});

where cinemascr is cached beforehand - I assume it's a static element on the page. In that case you can cache it on page load like so:

var cinemascr = $( '#cd_vk_cinemascreen' )[0];

It could be that IE7 doesn't like the format of the URL '/index.php?id=19'...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号