Any reason why having a javascript timer fire every 2.5 second for an ajax request to my own callback(listed below) that all it does is return the contents of 2 _session variables would take up so much resources?<br><br>John<br>
<br>function refreshcarttimer() {<br> print($_SESSION['num_items'] . ',' . $_SESSION['uc_price']);<br> return;<br>}<br><br>/**<br> * Implementation of hook_menu().<br> */<br><br>function product_type_menu() {<br>
$items = array();<br><br> $items['cart/refreshcarttimer'] = array(<br> 'title' => 'Refresh Shopping Cart',<br> 'description' => 'Refresh Shopping Cart',<br> 'page callback' => 'refreshcarttimer',<br>
'access callback' => TRUE, <br> 'type' => MENU_CALLBACK,<br> );<br> return $items;<br>} <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>
<div class="gmail_quote">On Sun, Feb 6, 2011 at 2:10 AM, John Mitchell <span dir="ltr"><<a href="mailto:mitchelljj98@gmail.com">mitchelljj98@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
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><font color="#888888"><br clear="all"><br><div style="display: inline;">
</div>-- <br>
John J. Mitchell<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>John J. Mitchell<br>