I am trying to get a table to update from my database. I have been trying to follow a php guide as it thought it would be quite similar but I can get it to work.
I have a separate file That gets the data and puts it into a table. Then im trying to use Javascript to get the file and refresh it.
This is my main file.
<module template="../includes/header.cfm" pagetitle = "Jaguar Live Capture">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<h1>Live Capture</h1><br />
<h2>Pen 1</h2>
<div id="tableHolder"></div>
</div><!--/span-->
</div><!--/row-->
This is my getData.cfm
<cfquery name="liveFeed">
SELECT * FROM details LIMIT 0, 10
</cfquery>
<style>
.oddRow{background:#ffffff;}
.evenRow {background: #DBDBDB;}
.warn{background:red;}
</style>
<table cellpadding="2">
<cfoutput query="liveFeed">
<cfif liveFeed.currentRow mod 2><cfset rowstyle = "oddRow">
<cfelse><cfset rowstyle = "evenRow">
</cfif>
<cfscript>
if (liveFeed.form_id == "" || liveFeed.first_name =="" || liveFeed.surname =="" || liveFeed.email ==""){ rowstyle = "warn";}
</cfscript>
<tr class="#variables.rowstyle#">
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.form_id#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.title#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.first_name#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.surname#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.email#</td>
</tr>
</cfoutput>
</table>
I have Tried a few pieces of javascript and ajax but have had no success. Can anyone help me create the script to refresh the page.
I am trying to get a table to update from my database. I have been trying to follow a php guide as it thought it would be quite similar but I can get it to work.
I have a separate file That gets the data and puts it into a table. Then im trying to use Javascript to get the file and refresh it.
This is my main file.
<module template="../includes/header.cfm" pagetitle = "Jaguar Live Capture">
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<h1>Live Capture</h1><br />
<h2>Pen 1</h2>
<div id="tableHolder"></div>
</div><!--/span-->
</div><!--/row-->
This is my getData.cfm
<cfquery name="liveFeed">
SELECT * FROM details LIMIT 0, 10
</cfquery>
<style>
.oddRow{background:#ffffff;}
.evenRow {background: #DBDBDB;}
.warn{background:red;}
</style>
<table cellpadding="2">
<cfoutput query="liveFeed">
<cfif liveFeed.currentRow mod 2><cfset rowstyle = "oddRow">
<cfelse><cfset rowstyle = "evenRow">
</cfif>
<cfscript>
if (liveFeed.form_id == "" || liveFeed.first_name =="" || liveFeed.surname =="" || liveFeed.email ==""){ rowstyle = "warn";}
</cfscript>
<tr class="#variables.rowstyle#">
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.form_id#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.title#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.first_name#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.surname#</td>
<td onclick="window.open('update.cfm?form_id=#liveFeed.form_id#', 'Update Details', 'width=350, height=350'); return false;">#liveFeed.email#</td>
</tr>
</cfoutput>
</table>
I have Tried a few pieces of javascript and ajax but have had no success. Can anyone help me create the script to refresh the page.
Share Improve this question edited Sep 10, 2012 at 10:05 Will asked Sep 10, 2012 at 9:59 WillWill 3,04431 silver badges44 bronze badges 1- Do you have the option of using jQuery? – Jason Dean Commented Sep 10, 2012 at 11:54
3 Answers
Reset to default 3Try this...
<script type="text/javascript">
window.setInterval(function(){$('#tableHolder').load('/getData.cfm');}, 6000);
</script>
setInterval is used to fire our anonymous function every 60 seconds.
The anonymous function uses the jQuery .load() function to get a files HTML from the server and replace the selected elements HTML with it.
You could use the cfdiv
tag to manage the AJAX request for you:
<cfdiv id="tableHolder" bind="url:getData.cfm" />
You could then use the ColdFusion.navigate function to reload or change the URL of that div.
ColdFusion.navigate('getData.cfm', 'tableHolder');
You can do this very simply with jQuery load(). load() will make an async request to the page and then load the response into the specified element.
<script src="https://ajax.googleapis./ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
$(function(){
$('#tableHolder').load('getData.cfm');
});
</script>
Trying copying the above into your page.