alex4412 Posted August 15, 2007 Share Posted August 15, 2007 How would I make this refresh every say five seconds? I found this but I'm not to sure how to implement this into the script... http://codeidol.com/ajax/ajaxdp/Browser-Server-Dialogue/Periodic-Refresh/ <html> <head> <title>Boards 'R' Us</title> <link rel="stylesheet" type="text/css" href="boards.css" /> <script type="text/javascript" src="text-utils.js"> </script> <script language="javascript" type="text/javascript"> var request = null; function createRequest() { try { request = new XMLHttpRequest(); } catch (trymicrosoft) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { request = null; } } } if (request == null) alert("Error creating request object!"); } function getBoardsSold() { createRequest(); var url = "boardSales.php"; request.open("GET", url, true); request.onreadystatechange = updatePage; request.send(null); } function updatePage() { if (request.readyState == 4) { var newTotal = request.responseText; var boardsSoldEl = document.getElementById("boards-sold") var cashEl = document.getElementById("cash"); replaceText(boardsSoldEl, newTotal); var priceEl = document.getElementById("price"); var price = getText(priceEl); var costEl = document.getElementById("cost"); var cost = getText(costEl); var cashPerBoard = price - cost; var cash = cashPerBoard * newTotal; cash = Math.round(cash * 100) / 100; replaceText(cashEl, cash); } } </script </head> <body> <h1>Boards 'R' Us :: Custom Boards Report</h1> <div id="boards"> <table> <tr><th>Snowboards Sold</th> <td><span id="boards-sold">1012</span></td></tr> <tr><th>What I Sell 'em For</th> <td>$<span id="price">249.95</span></td></tr> <tr><th>What it Costs Me</th> <td>$<span id="cost">84.22</span></td></tr> </table> <h2>Cash for the Slopes: $<span id="cash">167718.76</span></h2> <form method="GET"> <input value="Show Me the Money" type="button" onClick="getBoardsSold();"/> </form> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/65128-periodic-refresh-first-week-w-ajax/ Share on other sites More sharing options...
Daniel0 Posted August 15, 2007 Share Posted August 15, 2007 setinterval('getBoardsSold()', 5000) Note that the second argument is in milliseconds... Link to comment https://forums.phpfreaks.com/topic/65128-periodic-refresh-first-week-w-ajax/#findComment-325105 Share on other sites More sharing options...
alex4412 Posted August 16, 2007 Author Share Posted August 16, 2007 How do I put it into the script though? Sorry I'm really new to this and I've been doing a ton of tutorials. Link to comment https://forums.phpfreaks.com/topic/65128-periodic-refresh-first-week-w-ajax/#findComment-325689 Share on other sites More sharing options...
Daniel0 Posted August 16, 2007 Share Posted August 16, 2007 You could put it before the closing script tag (</script>) in the <head> tag. Note that in the code you posted you only wrote </script Link to comment https://forums.phpfreaks.com/topic/65128-periodic-refresh-first-week-w-ajax/#findComment-325692 Share on other sites More sharing options...
alex4412 Posted August 16, 2007 Author Share Posted August 16, 2007 On setinterval('getBoardsSold()', 5000) the "I" on interval wasn't capitalized Thank you Daniel0 for the help! Link to comment https://forums.phpfreaks.com/topic/65128-periodic-refresh-first-week-w-ajax/#findComment-325708 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.