JavaScript - Cancel Previous Refresh Request Before New Refresh
Hi,
I have the below code: Code: <script type="text/javascript"> function loadQuickMessageCheck(File,ID){ var xmlhttp; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById(ID).innerHTML=xmlhttp.responseText; eucalyptus = setInterval(function(){loadQuickMessageCheck(File,ID)},20000); } } xmlhttp.open("POST",File,true); xmlhttp.send(); } </script> But I am overloading the server and crashing it. I've googled the issue and have found people with similar problems who talk about the need to cancel the last refresh request before they send the next refresh. I even found this nice piece of code which worked for someone else. Quote: try{window.clearTimeout(tRefresh)} catch(err) {} tRefresh = setInterval(setContext, varInterval*60*1000); } I am not sure if this is the solution that I am looking for but if it is all my attempts at applying this code has been a bit of a disaster. Similar TutorialsHi I need some help. I have a link that opens in a new window which allows the user to perform an update to a record. On submit I want it to obviously update (which it does), then close the page and update the main page (where we opened the link from initially). I seem to have this working using an function which is called off the submit button using onclick........the function is: <script type="text/javascript"> function windowclose() { window.opener.location.href = window.opener.location.href; window.close() } </script> Now, the update happens as I say, and the page closes, and the main page looks like it refreshes but the update is not reflected....if I hit f5 the update appears. Is it to do with the speed of writing to the database and updating the screen? I have also been playing around with trying to add a settimeout to add a delay between update and close/refresh but couldnt get it to work. Any help would be appreciated. Cheers! Here is my calander script PHP Code: <script src="http://www.runningprofiles.com/jquery.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/members/diary/facebox/facebox.css" media="screen" rel="stylesheet" type="text/css"> <script src="http://www.runningprofiles.com/members/diary/facebox/facebox.js" type="text/javascript"></script> <script> jQuery(document).ready(function($) { $('a[rel*=facebox]').facebox() }) </script> <?php // there is NO NEED to edit ANY of this code $ev_dat = array(); for ($i=0;$i<32;$i++) { $ev_dat[$i]=0; } $now = date("Y-m-d", time()); list($ty, $tm, $td) = explode('-',$now); // ty=thisyear, etc. used for highlighting 'today' include("cal_parms.php"); // assorted configuration variables include($dat_names); // retrieved from cal_parms.php as a 'language' file if (!isset($_GET['m'])) { $m = date("m",mktime()); } else { $m = $_GET['m']; } if (!isset($_GET['y'])) { $y = date("Y",mktime()); } else { $y = $_GET['y']; } /*== get what weekday the first is on ==*/ $tmpd = getdate(mktime(0,0,0,$m,1,$y)); $month = $tmpd["month"]; $firstwday= $tmpd["wday"]; if ($firstDayIsMonday == 1) { if ($firstwday == 0) { $firstwday = 6; } else { $firstwday--; } } $lastday = mk_getLastDayofMonth($m,$y); /*== get the last day of the month ==*/ function mk_getLastDayofMonth($mon,$year) { for ($tday=28; $tday <= 31; $tday++) { $tdate = getdate(mktime(0,0,0,$mon,$tday,$year)); if ($tdate["mon"] != $mon) { break; } } $tday--; return $tday; } // compute range of dates for this month to match dates in database in the format yyyy-mm-dd if (strlen($m)<2) { $q="0"; $q.=$m; } else { $q = $m; } $dats_beg = $y. "-". $q. "-01"; $dats_en = $y. "-". $q. "-". $lastday; // open db conn and select all records where date is between $dats_beg and $dats_en include("cal_db_conn.php"); mysql_connect($db_host, $db_login, $db_pass) or die ("Can't connect!"); mysql_select_db($db_name) or die ("Can't open database!"); $query = "SELECT * FROM $db_table WHERE (ev_dat>='$dats_beg') AND (ev_dat<='$dats_en') "; $result = mysql_db_query($db_name, $query); // any matches? if ($result) { // handle the matches and pass relevant info to arrays while ($myrow = mysql_fetch_array($result)) { $found = $myrow['ev_dat']; $pieces = explode("-", $found); $dd = intval($pieces[2]); $ev_dat[$dd] = $myrow['id']; } } ?> <table cellpadding="1" cellspacing="1" border="0" bgcolor="#<? echo $bg_edge; ?>"> <tr><td colspan="7" bgcolor="#<? echo $bg_top; ?>"> <table cellpadding="1" cellspacing="1" border="0" width="100%"> <tr bgcolor="#<? echo $bg_top; ?>"><th width="20" style="<?php echo $hcell; ?>"><a href="<? echo $username; ?>&m=<?=(($m-1)<1) ? 12 : $m-1 ?>&y=<?=(($m-1)<1) ? $y-1 : $y ?>"><img src='http://www.runningprofiles.com/calendar/images/prev.gif' height='18' width='18' alt='' border='0' /></a></th> <th style="<?php echo $hcell; ?>"> <?php echo "<a href='../members/diary/show-month.php?mon=". $m. "&yr=". $y. "'rel=\"facebox\">"; echo "<span style='text-decoration:none'>". $mo[intval($m)]. " ". $y. "</span></a>"; ?> </th> <th width="20" style="<? echo $hcell; ?>"><a href="<? echo $username; ?>&m=<?=(($m+1)>12) ? 1 : $m+1 ?>&y=<?=(($m+1)>12) ? $y+1 : $y ?>"><img src='http://www.runningprofiles.com/calendar/images/next.gif' height='18' width='18' border='0' alt='' /></a></th> </tr> </table> </td></tr> <tr bgcolor="#<? echo $bg_top; ?>"> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[1]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[2]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[3]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[4]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[5]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[6]; ?></th> <th width="20" style="<?php echo $hcell; ?>"><? echo $da[7]; ?></th> </tr> <? $d = 1; $wday = $firstwday; $firstweek = true; /*== loop through all the days of the month ==*/ while ( $d <= $lastday) { /*== set up blank days for first week ==*/ if ($firstweek) { if ($wday!=0) { echo "<tr bgcolor='#". $bg_tabl. "'>\n"; for ($i=1; $i<=$firstwday; $i++) { echo "<td style='". $tcell. "' bgcolor='#". $bg_fill. "'> </td>\n"; } } /*== Sunday start week with <tr> ==*/ else { echo "<tr bgcolor='#". $bg_tabl. "'>\n"; } $firstweek = false; } /*== check for event ==*/ echo "<td style='". $tcell. "' "; // is this day 'today' AND there's no event today if (($ty==$y) && ($tm==$m) && ($td == $d) && (!$ev_dat[$d])) { echo "bgcolor='#". $bg_now. "'>". $d; } elseif ($ev_dat[$d]) { // get what's happening that day and use as 'mouseOver' for the link $query = "SELECT * FROM $db_table WHERE id=$ev_dat[$d] "; $result = mysql_query($query); $ev = mysql_fetch_array($result); $titl = $ev['ev_title']; echo "bgcolor='#". $bg_act. "'>"; $url = "../members/diary/show.php?event=". $ev_dat[$d]. "&sho=". $win_sho; echo "<a href=' $url' rel=\"facebox\" title=\"". $titl. "\">". $d. "</a>"; } else { echo "bgcolor='#". $bg_days. "'>". $d; } echo "</td>\n"; /*== Saturday end week with </tr> ==*/ if ($wday==6) { echo "</tr>\n"; } $wday++; $wday = $wday % 7; if (($wday==0) AND ($d!=$lastday)){ echo "<tr bgcolor='#". $bg_tabl. "'>\n"; } $d++; } // and close off the table if (($wday!=7) AND ($wday!=0)) { for ($i=$wday; $i<=6; $i++) { echo "<td style='". $tcell. "' bgcolor='#". $bg_fill. "'> </td>\n"; } echo "</tr>"; } echo "\n</table>"; include("win_open.php"); ?> what would be the best way to make it so that if you wish to chnage the month it changed the month on page rather than refresh the whole page its on? Hi there, I'm working on a presentation and I'm going to store each page into a ".html" So in example, I have... "1.html" "2.html" "3.html" Each number goes to each slide accordingly. The way I was working the presentation out was having users load a webpage via mobile phone which contains an iframe. I'll change the src of the iframe to the desired slide; and the META refresh will handle displaying it to the user. Now, here's the problem. It flashes on some browsers, like Blackberries. I'd like for the content being refreshed to not flash, but appear naturally. That way, the user doesn't have to attempt to read flashing text (which gets -REALLY annoying) ------------------------------------ TLDR; I need some code to refresh a page/div without flashing the content on ALL if not MOST browsers. Thanks. ------------------------------------ I think I know how I'd solve this issue; but I'm not too sure how to "integrate it" Perhaps, have a Javascript code keep the current "look" of the page static until "X" seconds. So, this would happen. Page refresh -> Javascript holds page for 5 seconds -> Page finishes loading -> Original page revealed It'd act kind of like a cover-up. Hi Frnds, I have faced some problem i.e I have 2 jsp pages.In that I want to go one jsp to another jsp.In 2nd jsp i can show my captcha code,but unfortunately it is not visible first page is reloaded in IE6.Once you refresh the page it's visible in IE6.So please help me to avoid this problem. Thanks, Whenever I update my website, sometimes I notice my browser shows the old version or a modification in the browser after I upload to the ftp. Whats the best way to prevent this from happening? Preferably without noticing it happening. Thanks. Well first off all I would appricate any help that you could give me because I've been looking all over the internet for the solution without any result. So off to my problem, I made this text-based online game and let's say the user does a crime, he did this crime 17:04:30 and has to wait till 17:06:30 before he can do a crime again (this is printed in the MySQL database). Getting the value from the database and changing it into the right format mm:ss is no problem. The problem comes to when its about refreshing... I've tried meta refresh and javascript location.refresh with good results, i sat the timer to 1 sec and it refreshed. The problem comes to when it refresh the mouse cursor and the tab (in firefox and chrome) gets that look, like when u refresh a page normally u can see an hourglass and all that. Is there anyway to disable that? And i think it really slows the browser down after a while (because after like 30 min or more firefox used 600 mb of my RAM). So yeah here's my Iframe code: Code: print <<<ENDHTML <IFrame Src= "right_timer.php" Scrolling=No Frameborder=0 Marginheight=0 Marginwidth=0 Width=100% Height=160> <p>Your browser does not support iframes.</p> </iframe> Also here's the right_timer.php: Code: <?php include("config.php"); $dbres = mysql_query("SELECT *,UNIX_TIMESTAMP(`crime`) AS `crime` FROM `users` WHERE `login`='{$_SESSION['login']}'"); $data = mysql_fetch_object($dbres); if(! check_login()) { print"<link rel=stylesheet type=text/css href=style.css>";exit; } if ($data->status == dead) { print"<link rel=stylesheet type=text/css href=style.css>";exit; } ?> <html> <head> <meta http-equiv="refresh" content="1"> </head> <body> <?php $dbres = mysql_query("SELECT * FROM `users` WHERE `activated`='1'"); $users= mysql_num_rows($dbres); $dbres = mysql_query("SELECT * FROM `users` WHERE `status`='alive' AND `activated`='1'"); $levend = mysql_num_rows($dbres); $dbres = mysql_query("SELECT * FROM `users` WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(`online`) < 300"); $online = mysql_num_rows($dbres); $dbres = mysql_query("SELECT * FROM `users`"); while($blah = mysql_fetch_object($dbres)){ $time = time(); $crime = gmdate('i:s',($data->crime - $time)); if (($data->crime - $time) < 0) { $crime = Now; } } print <<<ENDHTML <tr><td>Crime {$crime}</td></tr> ENDHTML; ?> </body> </html> I am trying to submit a hidden text area from a WYSIWYG editor. Its submitting the subject line which is a standard text input but its not submitting the text area. I can only think its because there are html tags in the submitted data. Is there a way to compensate for this or will I have to give up trying. This works on one of our other sites, but today I noticed this site is having a problem, its just not refreshing at all... here is the code.. (what is used on the iframe) Code: <iframe id="ad1" whats in the header (besides the including of the js file) Code: <script type="text/javascript"> var imageIntervals={}; var imageLimit={}; var imageCount={}; </script> and the actual script Code: function toggleImage(id) {if(imageCount[id]<imageLimit[id]||imageLimit[id]<0) {var img=document.getElementById(id);img.src=img.src;imageCount[id]++;}else {clearInterval(imageIntervals[id]);}} function setImageInterval(id, ms, limit) {imageIntervals[id]=setInterval("toggleImage('"+id+"')", ms);imageLimit[id]=(limit!==undefined?limit:-1);imageCount[id]=0;} /* IFERAME RATES */ window.onload=function() { setImageInterval("ad1", 72000, 4); setImageInterval("ad2", 60000, 4); setImageInterval("ad3", 66000, 4); setImageInterval("ad4", 72000, 4); setImageInterval("ad5", 72000, 4); setImageInterval("ad6", 76000, 4); } This should work, but its not so trying to see if you can see something I dont. If theres a better iframe refresh script out there that can do different intervals, please share. Thanks Is there a way to call a javascript function in a meta refresh statement? I'm refreshing my page but if I have data in my fields I don't want to loose them. If I can call using a JS function then in that function I can call the Submit function and save my data in the called script. My syntax below doesn't fire the JS function: PHP Code: <meta http-equiv="refresh" content="30;url=javascript:auto_refresh();"> Okay, so I'm making something so IF the number is BETWEEN this number, and that number, I want it to display a certain number. Ex. Code: var Num1 = 100 var Num2 = 200 var Num3 = 1 If (Num1{THIS IS WHAT I DON'T KNOW}Num2) { alert(Num3) } Also, could somebody please tell me what those are called? The; == != || etc. Because I was having a TERRIBLE time trying to google that. AHH! I'm sorry for this. I know this is a stupid question. Hi, I have an onclick handler as: onClick="window.open ('test.cgi?action=testfile', 'testframe')" When clicked on the button for the first time, request is sent to webserver and target file for "testfile" action is getting loaded in frame testframe. But when i click for the second time, request is not sent to webserver and the cached entry is getting loaded. This issue is occuring only in IE but not in FF. I went to the cached data in c:\Documents and settings\<user>\...\Temporary Internet Files\ and i'm seeing that targetfile for test.cgi?action=testfile is getting stored and "last accessed" time stamp is updated but the "last checked" value is not getting updated (when ever i click on the button). But no issue is seen when the onclick handler is like below: onClick="document.location='test.cgi?action=testfile' I could not understand what exactly is the issue: Is it with Frames/window.open/Do i have to remove cached entries? etc... Can any one please help me out on how i can proceed with this... Please let me know if i'm not clear with above description. Thanks in advance... i have a page named pck_rates.php which contains a form that go to the page update_pck_rates.php when i press updade data button in the second page i want the first page to be refreshed to show the new data's. i want to know if i can set a name to the page pck_rates.php and after the update query in the second page i will refresh the pck_rates.php page using this name?? i don't know what is the function and how to make this idea. can anyone help me please Hi to all, I got a timestamp (in the future) and I want to display on a page how many seconds this differs from now. I know how to do this in PHP, but now it's static, I want it to actually count down. After the countdown, the page should be refreshed, although I could also do this with a meta tag, as I can just find the value with PHP on load and put that value in a meta refresh tag. Could you help me out with one of these things? x5x_tim Okay, I assume many will think I must have missed the previous thread, but I did look at it, and I am not sure if that one comes close to answering my idea here. I was looking at NHL.com, and I noticed the scoreboard changed without me reloading the page. So... I looked at the code, and this is where I got completely lost: Code: <div id="scoreboard"> <style type="text/css"> #masthead #richMedia, #scoreboard { margin-left: 0px; width: 817px; } </style> <script src="/js/hdr_scoreboard.js?v=6" language="JavaScript" type="text/javascript"></script> <script language="JavaScript" type="text/javascript"> var dataSource = "http://live.nhle.com/GameData/PlayoffScoreboard.jsonp?loadScoreboard=?"; jQuery(document).ready(function() { initScoreboard(5, 'cc0000', '000000'); }); </script> What I am interested in doing is reloading an iframe that has a total visitor counter. That way say every 5 minutes or so, it gets updated without any interaction needed. I tried the meta refresh on the iframe's target page long ago, but that forced a reload on the main page as well, and I am totally against doing that. So, does anyone here have any tips to provide? I have a page with 2 iframes how can I make it that if they submit on the first iframe - it should refresh the second iframe? hi i have a table with some document.write statements inside that write inside the cells. i need to refresh the table from a function so the statements will execute again. but i only want the table to refresh not the whole page document.location.reload() this does the page but can i put the tables id in the brackets or something. thanks Now I have a page with Text boxes, and dropdown boxes on the page and 3 buttons. While this is mainly PHP the aspect that I need at the moment is in Javascript. On click the 1st submit button, "Preview", it shows a table and another button. But the form below is cleared as it refreshed the page. I want to know if it is possible that I can set the fields to the values that the user set before they clicked the button to show the table since it clears them. I've thought of 2 ways to do it but I have no idea how to do either of them. 1: The reset button resets all the variables to the page load default which is blank or 0 according to which field. Because I know a way to do it but then my reset button doesn't clear anything... 2: Onclick of the Preview button, the values are set but not the same way as the PHP one since that sets them until you do a hard reload of the page. Code: var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no) var loadedobjects="" var rootdomain="http://"+window.location.hostname var bustcacheparameter="" function ThinkHabbo(url, containerid){ var page_request = false if (window.XMLHttpRequest) // if Mozilla, Safari etc page_request = new XMLHttpRequest() else if (window.ActiveXObject){ // if IE try { page_request = new ActiveXObject("Msxml2.XMLHTTP") } catch (e){ try{ page_request = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} } } else return false page_request.onreadystatechange=function(){ loadpage(page_request, containerid) } if (bustcachevar) //if bust caching of external page bustcacheparameter=(url.indexOf("?")!=-1)? "&"+new Date().getTime() : "?"+new Date().getTime() page_request.open('GET', url+bustcacheparameter, true) page_request.send(null) } function loadpage(page_request, containerid){ if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1)) document.getElementById(containerid).innerHTML=page_request.responseText } function loadobjs(){ if (!document.getElementById) return for (i=0; i<arguments.length; i++){ var file=arguments[i] var fileref="" if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding if (file.indexOf(".js")!=-1){ //If object is a js file fileref=document.createElement('script') fileref.setAttribute("type","text/javascript"); fileref.setAttribute("src", file); } else if (file.indexOf(".css")!=-1){ //If object is a css file fileref=document.createElement("link") fileref.setAttribute("rel", "stylesheet"); fileref.setAttribute("type", "text/css"); fileref.setAttribute("href", file); } } if (fileref!=""){ document.getElementsByTagName("head").item(0).appendChild(fileref) loadedobjects+=file+" " //Remember this object as being already added to page } } } Is there any chance i can add a refresh timer to this? I need help with a javascript refresh button. I'm having trouble linking the feed fetcher section to the refresh button section. I think code lines 81 through 87 are the problem. [code] // create table view data object var data = []; var xhr = Ti.Network.createHTTPClient(); xhr.open("GET","http://rss.news.yahoo.com/rss/business"); xhr.onload = function() { try { var doc = this.responseXML.documentElement; var items = doc.getElementsByTagName("item"); var x = 0; var doctitle = doc.evaluate("//channel/title/text()").item(0).nodeValue; for (var c=0;c<items.length;c++) { var item = items.item(c); var thumbnails = item.getElementsByTagName("media:thumbnail"); var media; if (thumbnails && thumbnails.length > 0) { media = thumbnails.item(0).getAttribute("url"); } else { media="blue.png"; } var title = item.getElementsByTagName("title").item(0).text; var row = Ti.UI.createTableViewRow({height:80}); var label = Ti.UI.createLabel({ text:title, left:72, top:5, bottom:5, right:5 }); row.add(label); var img; if (Titanium.Platform.name == 'android') { // iphone moved to a single image property - android needs to do the same img = Ti.UI.createImageView({ url:media, left:5, height:60, width:60 }); } else { img = Ti.UI.createImageView({ image:media, left:5, height:60, width:60 }); } row.add(img); data[x++] = row; row.url = item.getElementsByTagName("link").item(0).text; } var tableview = Titanium.UI.createTableView({data:data}); Titanium.UI.currentWindow.add(tableview); tableview.addEventListener('click',function(e) { var d=Titanium.Platform.openURL(e.row.url); }); // START REFRESH code var refresh = Titanium.UI.createButton({ systemButton:Titanium.UI.iPhone.SystemButton.REFRESH }); refresh.addEventListener('click', function() { tableview.Data([]); setTimeout(function() { Data(); },1000); }); if (Ti.Platform.name == 'iPhone OS') { win2.rightNavButton = refresh; } else { refresh.top = 5; refresh.title = "Refresh"; refresh.width = 200; tableview.top = 60; Titanium.UI.currentWindow.add(refresh); } Data(); //END REFRESH code } catch(E) { alert(E); } }; xhr.send(); [code] I'm making a chess game and I have a couple of problems. one, for some reason I need to refresh the page for it to fully load http://ktownsend.shorelinevct.net/chess/ two, hiding the available moves only works when I click on a different piece. when clicking on the same piece I get an err.message which says that the pieces this.availMoves[i] = null. which doesn't make sense. I get the same err.message when I click on a different piece but it works anyway. when I click on the same piece it doesn't work at all. Any help would be appreciated |