Fadi February 2016

Html5 data attribute is not updating after ajax request

i have two data attributes one in decreasing every second and is 0 when the first attribute reach 0 an ajax request is send to get the second data value but when i set the value to the second data attribute is not changed in html but when i printed it changed !!!

my code

       setInterval(
        function () {

            if ($j('#auctions-widget .auction_hours').length) {
                var auctions_hours = [];
                $j('#auctions-widget .auction_hours').each(function () {
                    auctions_hours.push($j(this).data('auction-id'));
                });
                for (var i = 0; i < auctions_hours.length; i++) {
                    checkAuctionHours(auctions_hours[i]);
                }
            }
        }
        , 1000);

 function checkAuctionHours(auction_id) {

        //var TimeWorker =  new Date();

        var auction_hours = $j("body").find(".auction_hours[data-auction-id='" + auction_id + "']");

        if (auction_hours.length) {
            //if(auction_id == 1637 && (auction_hours.data("open-contest-hours") !=0 || auction_hours.data("close-contest-hours")!=0) ){
            //console.log('time to open-contest-hours: ' + auction_hours.data("open-contest-hours") + ' id= ' + auction_id);
            //console.log('time to close-contest-hours: ' + auction_hours.data("close-contest-hours") + ' id= ' + auction_id);
            //}
            if (auction_hours.data("open-contest-hours") != 0) {
                auction_hours.data("open-contest-hours", auction_hours.data("open-contest-hours") - 1);
                console.log('time to open-contest-hours: ' + auction_hours.data("open-contest-hours") + ' id= ' + auction_id);
                //validate_auctions_hours_time(auction_id, 'open');
                //console.log('open');
                //console.log(auction_id);
                if (auction_hours.data("open-contest-hours") == 0) { //time to open auction based on auction hours
              

Answers


Fadi February 2016

finally i try to replace all the auction_hours.data with auction_hours.attr in all the code and it work fine.

Post Status

Asked in February 2016
Viewed 2,174 times
Voted 6
Answered 1 times

Search




Leave an answer