开发者

Safari/Webkit processing function too early after ajax:complete

i have an ajax call i am doing and its working just fine. thing is, i need the dimensions of an image. i cant declare these dimensions in html, cause they are dynamically resized. now if i call a function during my complete state, for fetching these dimensions, webkit browsers put out 0, while FF puts out the correct dimensions.

$.ajax({
        url: event.path,
        cache: false,
        error: function开发者_如何转开发(XMLHttpRequest, textStatus, errorThrown) {
            handler(XMLHttpRequest.responseText);
        },
        success: function(data, textStatus, XMLHttpRequest) {
            handler(data);
        },
        complete: function() {
            textBoxWidth();
        }
    });

and this is the called function

function textBoxWidth() {
    $("#project .textBox").css("width", $("#project .imgBox:last img").width());
}

any suggestions for this? i tried

if (jQuery.browser.safari && document.readyState != 'complete')

but the document state isnt changing at all, once the DOM is ready..

thanks.


another example, of how to let jquery wait while loading is jQuery.active.

its a variable that spits out 1, if jquery is still loading and 0 if its finished.

$.ajax({
        url: path,
        cache: false,
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            handler(XMLHttpRequest.responseText);
        },
        success: function(data, textStatus, XMLHttpRequest) {
            handler(data);
        },
        complete: function() {
            if (jQuery.active !== 0) {
                setTimeout( arguments.callee, 100 );
                return;
            }
            //fancyFunction();
        }
    });


okay. after hacking around a little bit i tried the following sollution, which works.

$.ajax({
        url: event.path,
        cache: false,
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            handler(XMLHttpRequest.responseText);
        },
        success: function(data, textStatus, XMLHttpRequest) {
            handler(data);
        },
        complete: function() {
            var imgCount = $("#project .content").find("img");
            if (imgCount.length > 0) {
                if ($("#project .content img:last").width() == 0) {
                    setTimeout( arguments.callee, 100 );
                    return;
                }
            //fancyFunction();
            }
        }
    });

so what i did: looking for images in my target div. if there are images around, and if the width of my last image is equal zero: redo the check for the width 100 ms later. else continue with whatever..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜