I have a javascript timer set to fire every 2.5 seconds so that I can set the current values for the items and total for the shopping cart summary. I would like to be able to get these values from client side cookies or javascript global variables so that I don't have to make an ajax call to the server but I have found that the DOM elements are not accessible within the javascript function unless I run an ajax request to a page (listed below) and after it returns then the DOM elements are accessible (i.e. $(".num-items").html(numItems);) and now I can update them. Having these ajax requests run every 2.5 seconds for every client will not scale.<br>
<br>How can I make Drupal DOM elements accessible within a javascript function without having to do an ajax request to a page?<br><br>Thanks,<br><br>John<br><br> setInterval('updateShoppingCartInfo()', 2500);<br>
<br> function updateShoppingCartInfo(){<br> var xmlHttpReq = new XMLHttpRequest();<br> var url = 'https://' + document.domain + '/cart/refreshcarttimer';<br> xmlHttpReq.open('post', url, true);<br>
xmlHttpReq.onreadystatechange = function() {<br> if (xmlHttpReq.readyState != 4) { <br> return; <br> }<br> else {<br> var responseText = xmlHttpReq.responseText;<br>
var numItems = responseText.substr(0,responseText.indexOf(","));<br> var ucPrice = responseText.substr(responseText.indexOf(",")+1);<br> $(".num-items").html(numItems);<br>
$(".uc-price").html(ucPrice);<br> } <br> }<br> xmlHttpReq.send(null);<br> } <br><br clear="all"><br><div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup">
</div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style>-- <br>
John J. Mitchell<br>