2015-12-21 46 views
1

我不擅長JavaScript,Ajax & Jquery,但我仍然必須完成一項任務。我試圖在運行時顯示更新的記錄數。這將是管理的實時報告,數量應該改變而不刷新頁面。我試圖寫一個腳本,但仍然失敗。在網上找到一個jquery腳本,我修改了它,但沒有得到想要的結果,我收到一個錯誤。我沒有從谷歌搜索中找到有用的例子。如果您有任何支持或有幫助的例子,請分享。Coldfusion:顯示數據庫更新總數cfajaxproxy

這是我做過什麼,到目前爲止:

CFC:計數器功能只是運行一個循環,但實際上這裏生病從數據庫中讀取數據。

<cfcomponent> 
<cffunction name="counter" returntype="any" access="remote" > 
    <cfset var o= 1> 
    <cfloop index="b" from="1" to="1000"> 
     <cfset o = b> 
     <cfset sleep = 1000> 
    </cfloop> 
<cfreturn o> 
</cffunction> 

CFM文件:

<cfajaxproxy cfc="async" jsclassname="asyncjs" /> 
<!DOCTYPE html> 
<html> 
    <body> 
    <div id="saa"><span class="count">200</span></div> 
<div style="clear:both"></div> 
<div id="talkbubble"><span class="count">1421</span></div> 
<br /> 
    <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> 

    <script type="text/javascript"> 
     var objCfc = new asyncjs(); 
      objCfc.setAsyncMode(); 

      alert(objCfc.counter()); 
      $('.count').each(function() { 
       var i =300; 
       $(this).prop('Counter',0).animate({ 
        Counter: $(this).text() 
       }, { 
        duration: 4000, 
        easing: 'swing', 
        step: function() { 
         //$(this).text(Math.ceil(now) 

         $(this).text(i); 
        } 
       }); 
      }); 
     </script> 
    </body> 
</html> 

請指教...

+1

建議嗎?從你的問題中刪除混亂。例如,所有這些風格的東西都是無關緊要的。 –

+0

您的問題不需要CSS –

+2

您可以訪問http:// //.cfc?function=counter嗎?它是否返回正確的值並且沒有錯誤信息?如果它工作到目前爲止,我推薦https://api.jquery.com/jquery.get/ –

回答

2

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>AJAX CFM</title> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> 
 
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 
 

 
<script type="text/javascript"> 
 
var auto_refresh = setInterval(
 
function() 
 
{ 
 
$('#noteDiv').load('content_notes.cfm?_=' +Math.random()).fadeIn("slow"); 
 
}, 1000); // refresh every 10000 milliseconds 
 

 
</script> 
 
</head> 
 

 
<body> 
 

 

 
<cfdiv id="noteDiv" bind="url:content_notes.cfm"></cfdiv> 
 

 

 
</body> 
 
</html>

<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>Untitled Document</title> 
 
</head> 
 

 
<body> 
 
    <br> 
 
\t  ...DIV Content - Date Time : <cfoutput> #now()# </cfoutput> 
 
    <br> 
 
</body> 
 
</html>