javascript - Html5 data attribute is not updating after ajax request -
i have 2 data attributes 1 in decreasing every second , 0 when first attribute reach 0 ajax request send second data value when set value second data attribute not changed in html when printed 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')); }); (var = 0; < 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 open-contest-hours: ' + auction_hours.data("open-contest-hours") + ' id= ' + auction_id); //console.log('time 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 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 open auction based on auction hours //send ajax check; //console.log('open'); validate_auctions_hours_time(auction_id, 'open'); } } else if (auction_hours.data("close-contest-hours") != 0) { auction_hours.data("close-contest-hours", auction_hours.data("close-contest-hours") - 1); console.log('time close-contest-hours: ' + auction_hours.data("close-contest-hours") + ' id= ' + auction_id); //validate_auctions_hours_time(auction_id, 'close'); if (auction_hours.data("close-contest-hours") == 0) { //time close auction based on auction hours //send ajax check; //console.log('close'); validate_auctions_hours_time(auction_id, 'close'); } } else if (auction_hours.data("open-contest-hours") == 0 && auction_hours.data("close-contest-hours") == 0) { } else { } } }
ajax code
function validate_auctions_hours_time(auction_id, auction_hours_status) { $.ajax({ async: true, url: my_ajax_script.ajaxurl, type: 'post', data: ({ type: 'post', action: 'validate_auction_hours_time', auction_id: auction_id, auction_hours_status: auction_hours_status }), success: function (response) { var auction_hours = $("body").find(".auction_hours[data-auction-id='" + auction_id + "']"); var auction_hours_img = ''; if (response.time_status == 'ok') { if (response.auction_hours_open_time) { //close auction till next auction hours //auction_hours.data('open-contest-hours', response.auction_hours_open_time); auction_hours.attr('data-open-contest-hours', response.auction_hours_open_time); console.log(auction_hours.attr('data-open-contest-hours')); auction_hours_img = $("body").find(".open-hours-active[data-auction-hours-img='" + auction_id + "']"); auction_hours_img.removeclass('open-hours-active'); auction_hours_img.parent().removeclass('auction_hours_blink').removeclass('auction_hours_reset_blink'); auction_hours_img.parent().addclass('auction_hours_blink'); auction_hours_img.addclass('open-hours-deactive'); $('#' + auction_hours_img.data('selector')).html(response.tool_tip); } else if (response.auction_hours_close_time) { //open auction till next auction hours //auction_hours.data('close-contest-hours', response.auction_hours_close_time); auction_hours.attr('data-close-contest-hours', response.auction_hours_close_time); console.log(auction_hours.attr('data-close-contest-hours')); console.log(auction_hours); auction_hours_img = $("body").find(".open-hours-deactive[data-auction-hours-img='" + auction_id + "']"); auction_hours_img.removeclass('open-hours-deactive'); auction_hours_img.parent().removeclass('auction_hours_blink').removeclass('auction_hours_reset_blink'); auction_hours_img.parent().addclass('auction_hours_blink'); auction_hours_img.addclass('open-hours-active'); $('#' + auction_hours_img.data('selector')).html(response.tool_tip); } } else if (response.time_status == 'reset') { if (response.auction_hours_open_time) { //sync auction auction hours auction_hours_img = $("body").find(".open-hours-deactive[data-auction-hours-img='" + auction_id + "']"); auction_hours.data('open-contest-hours', response.auction_hours_open_time); auction_hours_img.parent().removeclass('auction_hours_reset_blink').removeclass('auction_hours_blink'); auction_hours_img.parent().addclass('auction_hours_reset_blink'); } else if (response.auction_hours_close_time) { //sync auction auction hours auction_hours_img = $("body").find(".open-hours-active[data-auction-hours-img='" + auction_id + "']"); auction_hours.data('close-contest-hours', response.auction_hours_close_time); auction_hours_img.parent().removeclass('auction_hours_reset_blink').removeclass('auction_hours_blink'); auction_hours_img.parent().addclass('auction_hours_reset_blink'); } else { } } }, error: function (jqxhr, textstatus, errorthrown) { response_errors_handling(jqxhr, textstatus, errorthrown); } });
finally try replace auction_hours.data
auction_hours.attr
in code , work fine.
Comments
Post a Comment