2010-11-26 54 views
0

我伊特諾運行一個jQuery/ColdFusion的問題,請通過下列文件證明:jQuery multiple .load()剝離出ColdFusion Ajax控件?

cflayout.cfm:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
</head> 
<cflayout name="tabtest" type="tab"> 
    <cflayoutarea name="tab1" title="tab1" > 
      <span>This is tab 1</span> 
     </cflayoutarea> 
     <cflayoutarea name="tab2" title="tab2" > 
      <span>This is tab 2</span> 
     </cflayoutarea> 
</cflayout> 
</html> 

cfcontent.cfm:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<cfajaximport tags="cfform,cflayout-tab"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<!--commenting out the jquery loader is for when loading via cftest.html 
    When run on its own, uncomments it--> 
<!--<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>--> 
<script type="text/javascript"> 
    $(document).ready(function(){ 
      $("#fcontent").load("cflayout.cfm"); 
     }); 
</script> 
fcontent: 
<div id="fcontent"> 
</div> 
</html> 

cftest.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>CFLayout Test</title> 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
     $("#fdiv").load("cfcontent.cfm"); 
    }); 
</script> 
</head> 

<body> 
<div id="fdiv"> 
    </div> 
</body> 
</html> 

在現實生活中,cfcontent.cfm文件充當將流程重定向到其他頁面的分類頁面。

現在cflayout.cfm本身運行良好,就像cfcontent.cfm一樣。但試圖加載cftest.html和選項卡控件消失,好像通過多次使用jquery .load()已經「剝離」了控件。

有沒有人遇到過這個?這是一個已知的問題?由於實際的.html在這種情況下是繼承的,我不能用.cfm文件替換它,而使用cfinclude。

關於我應該如何重新構建我的方法的任何建議?

+2

您可能需要使用cfajaximport父頁面上,確保爲您cflayout腳本被加載。 – Henry 2010-11-26 20:12:17

回答

0

在我使用jQuery的經驗中,無論何時將新信息加載到頁面,通常都會失去新元素的javascript控件,除非您主動監視這些更改。在這種情況下,您需要確保由CF創建的ajax的javascript包含在頁面加載後運行。與其他jQuery頁面,我只需要綁定新的元素。有了Coldfusion AJAX控件,我不知道如何幫助你,因爲我們已經離開了他們。他們有時候太麻煩了。我明白這可能不適合你。

您可以認爲該http://api.jquery.com/jQuery.getScript/

0

這爲我工作:

$(".myTargetDIV").html('<cfoutput><cfinclude template="myColdFusion.cfm"></cfoutput>');