Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2013, 06:50 PM   PM User | #1
Catch84
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Catch84 is an unknown quantity at this point
Is Ajax right for me?

What I have works (kind of) but I am looking for a better way. What I have is an FTP script that runs every few minutes and gathers small .txt files from 5 different locations. I then use this to present that information.

Code:
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\Inetpub\wwwroot\Default\new_web\usbobs\"

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & strPathtoTextFile & ";" & _
          "Extended Properties=""text;HDR=No;FMT=Delimited"""

strFile = "cf.txt"

objRecordset.Open "SELECT * FROM cf.txt",_
          objConnection, adOpenStatic, adLockOptimistic, adCmdText

count = 4
do until count = 0



'Do Until objRecordset.EOF
       
  
 If objRecordset.Fields.Item("BobNumber") = "East Plytrim" Then Response.Write "<span style=""color: rgb(51,0,102);"">Bin: East Plytrim</span>" & "<br>"
 If objRecordset.Fields.Item("BobNumber") = "Center Plytrim" Then Response.Write "<span style=""color: rgb(51,0,102);"">Bin: Center Plytrim</span>" & "<br>"
 If objRecordset.Fields.Item("BobNumber") = "Saw Chips" Then Response.Write "<span style=""color: rgb(51,0,102);"">Bin: Saw Chips</span>" & "<br>"
 If objRecordset.Fields.Item("BobNumber") = "Plychips" Then Response.Write "<span style=""color: rgb(51,0,102);"">Bin: Plychips</span>" & "<br>"
	If objRecordset.Fields.Item("BinMeasure") >= 17 Then Response.Write "<span style=""color: red; font-weight:bold;"">High Level</span>" & "<br>"
    Response.Write "<span style=""color: rgb(0, 255, 255); font-weight:bold;"">Height: </span>" & "<span style=""color: rgb(0, 255, 255); font-weight:bold;"">" & objRecordset.Fields.Item ("percentage") & "</span>" & "<br>"
    If objRecordset.Fields.Item("Status") = "DISABLED" Then Response.Write "<span style=""color: red; font-weight:bold;"">Status: DISABLED</span>" & "<br>"
    If objRecordset.Fields.Item("Status") = "ENABLED" Then Response.Write "Status: ENABLED" & "<br>" 
    Response.Write "Status: " & objRecordset.Fields.Item("DateTime") & "<br>"
    Response.Write "<br>"


objRecordset.MoveNext

count = count - 1
 
Loop

objRecordset.close
I also use <meta http-equiv="refresh" content="300"> to refresh the browser every 5 min, but I'm sure this is not the best way to accomplish this. Would Ajax be the right way to go and if so could someone give me a shove in the right direction?
Catch84 is offline   Reply With Quote
Old 01-29-2013, 06:54 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 946
Thanks: 7
Thanked 97 Times in 97 Posts
WolfShade is an unknown quantity at this point
AJaX would be slightly better primarily because you can run it in the background and present the information without refreshing the page. Just make the call with AJaX and set an elements innerHTML to the returned value.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 01-30-2013, 12:30 AM   PM User | #3
Catch84
New to the CF scene

 
Join Date: Jan 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Catch84 is an unknown quantity at this point
Thanks WolfShade, this gives me a direction to head.
Catch84 is offline   Reply With Quote
Old 01-30-2013, 04:48 AM   PM User | #4
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
since you are spitting out HTML, this is a good candidate for my off-page content fetcher.
you would need to wrap all those spans in a container, say <div id=main>, and then you can easily inject that content into any page, and do so at a regular interval.


let's call your data page data.asp and your home page index.html (shown below, adjust as needed):

Code:
<!DOCTYPE html>
<html>
<head>
	<title>my home page</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body onload=redraw()>
  
  <h1>my home page</h1>
  
<h3>Latest Updates</h3>
<div id='container'>
	
</div>	


<script type='text/javascript'>


function redraw(){
    getPage("data.asp", "#main", "#container");
}


 setInterval(redraw, 1000 * 300); // repeat every 300seconds


function getPage(url, from, to) {
	var cached=0 // sessionStorage[url];
   	if(!from){from="body";} // default to grabbing body tag
	if(cached){return elm.innerHTML=cached;} // cache responses for instant re-use re-use
	if(to && to.split){to=document.querySelector(to);} // a string TO turns into an element
	if(!to){to=document.querySelector(from);} // default re-using the source elm as the target elm

	var XHRt = new XMLHttpRequest; // new ajax
	XHRt.responseType='document';  // ajax2 context and onload() event
	XHRt.onload= function() { sessionStorage[url]=to.innerHTML= XHRt.response.querySelector(from).innerHTML;};
	XHRt.open("GET", url, true);
	XHRt.send();
	return XHRt;
}



</script>
</body>
</html>
EDIT i turned off caching since this is for data, changes in red.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 01-30-2013 at 04:54 AM..
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:09 AM.


Advertisement
Log in to turn off these ads.