当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Chrome only updates with jquery.html() when debugging and hitting breakpoint

问题描述:

I've got the following snippet in my web page. It's suppose to temporarily change the inner HTML content of a container, when the user clicks a "BUY" button on the page.

//////////

// Add items to basket //

////////

function addToBasket(pageId, itemId, produktNumber, domElem) {

var tempHtml = $(domElem).html();

$(domElem).html('<i class="fa fa-refresh fa-spin"></i>');

$(domElem).attr('disabled', true);

// Update the cart

updateCart('/default.aspx?id=' + pageId + '&amp;productid=' + itemId + '&amp;quantity=' + $('#antal_' + produktNumber).val() + '&amp;cartcmd=add', undefined, false, domElem);

$(domElem).html(tempHtml);

$(domElem).removeAttr('disabled'); }

The second line in the function is only triggered in Chrome when I'm debuging... Anyone out the who has seen a simular problem?

It's works great in IE and FF - so I'm very confused right now...

** EDITED **

Okay... So I've edited the script according to advice I've been given - but the problem remains :( A actualy thought the ajaxComplete should fix it, but it doesn't... workingElement.html(''); seems to be skipped when running without breakpoints.. And ONLY in Chrome...

function addToBasket(pageId, itemId, produktNumber, domElem) {

var tempHtml = $(domElem).html();

var workingElement = $(domElem);

workingElement.html('<i class="fa fa-refresh fa-spin"></i>');

workingElement.attr('disabled', true);

$(document).ajaxComplete(function(){

workingElement.html(tempHtml);

workingElement.removeAttr('disabled');

});

// Update the cart

updateCart('/default.aspx?id=' + pageId + '&amp;productid=' + itemId + '&amp;quantity=' + $('#antal_' + produktNumber).val() + '&amp;cartcmd=add', undefined, false, domElem);

}

网友答案:

Anthony Grist got it right... The async call was the issue

网友答案:

You need to instantiate jQuery in your function if it is not wrapped already:

function addToBasket(pageId, itemId, produktNumber, domElem) { $(function() {

    // Your Code Here

}); }
分享给朋友:
您可能感兴趣的文章:
随机阅读: