2016-05-05 47 views
0

我想要當任一項目是從以下選擇列表中選擇要加載我的div內頁中選擇項:JQuery的:無法加載在DIV頁面時在選擇列表

<select id="opt"> 
        <option value="">-Select a Plan-</option> 
        <option value="bin">Binary MLM</option> 
        <option value="mat">Matrix MLM</option> 
        <option value="uni">Uni-Level MLM</option> 
        <option value="gen">generation MLM</option> 
       </select> 

當一個onchange事件triggerred,以下jQuery代碼:

$('#opt').on('change', function(event) { 
    var val = $(this).val(); 
    $.("#desc").load('/assets/pages/'+val+'.html.twig'); 
}); 

應在此跨度加載一個頁面:

<span id="desc"></span> 

但它不是那樣工作的。請幫我指出這裏的問題。還要注意這是一個symfony項目,並且要提取的頁面存儲在/ web/assets/pages目錄中(/ web可公開訪問),並且頁面的名稱與可以從select標籤中選擇的值相同。

+0

哈哈,那是愚蠢的..哎呀:/ –

回答

0

您應該使用其他行動中加載模板,像這樣:

/** 
* @Route("/load-template/{templateName}", name="frontend.load-template") 
*/ 
public function loadTemplateAction(Request $request, $templateName) 
{ 
    return $this->render(sprintf("%s:%s", "BundleName", $templateName)); 
} 
+0

請這個[URL](http://stackoverflow.com/help) ,將內容質量提高很有用 –