Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Thanked 0 Times in 0 Posts

    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.

    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>"
    count = count - 1
    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?

  • #2
    Regular Coder
    Join Date
    Apr 2012
    St. Louis, MO
    Thanked 101 Times in 101 Posts
    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".

  • #3
    New to the CF scene
    Join Date
    Jan 2013
    Thanked 0 Times in 0 Posts
    Thanks WolfShade, this gives me a direction to head.

  • #4
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 598 Times in 578 Posts
    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):

    <!DOCTYPE html>
    	<title>my home page</title>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <body onload=redraw()>
      <h1>my home page</h1>
    <h3>Latest Updates</h3>
    <div id='container'>
    <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);
    	return XHRt;
    EDIT i turned off caching since this is for data, changes in red.
    Last edited by rnd me; 01-30-2013 at 05:54 AM.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts