2011-12-14 25 views
0
下一個GSP頁面

我需要通過一個完整的HTML表中的內容,並試圖把它作爲一個參數去下一個GSP頁面的Ajax調用傳遞一個表HTML內容

jQuery.ajax({ 
      type:'POST', 
      data:{'table_cart': $("#table_cart").html()}, 
      url: '/gra/ar_request/nextpage', 
      beforeSend: function() { 
        jQuery('#templateDiv').html('show spinner') 
       }, 
      success:function(data,textStatus){jQuery('#templateDiv').html(data);}, 
      error:function(XMLHttpRequest,textStatus,errorThrown){}}); 
    return false; 

當我嘗試找回在下一頁中的值我得到各種類似的錯誤,如「XML沒有正確形成,期待img標籤,缺少..等等」

我只是試圖做下面的讀取值在下一頁

var table_content = ${table_cart} 

給予值附近的單引號給出錯誤。需要知道如何將表格的html內容傳遞給另一個gsp,有沒有更好的方法?

有關nextpage.gsp的錯誤詳情 缺失;聲明 http://cdn.jquerytools.org/1.2.6/full/jquery.tools.min.js 線29

I am doing 
<script> 
    var tbcont = ${rolecart} 
</script> 

之前,我打印出來從動作在控制檯上的內容和它有正確的內容。即表格中的所有標籤,我是否需要對html內容進行編碼? 從控制檯內容的確切顯示爲:

<thead> 
       <tr> 

        <th scope="col" style="width: 40%"> 
        <span class="column-sort"> 
         <a href="#" title="Sort up" class="sort-up"></a> 
         <a href="#" title="Sort down" class="sort-down"></a> 
        </span> 
        Role 
        </th> 
        <th scope="col" style="width: 55%"> 
        <span class="column-sort"> 
         <a href="#" title="Sort up" class="sort-up"></a> 
         <a href="#" title="Sort down" class="sort-down"></a> 
        </span> 
       Description 
        </th> 
       </tr> 
       </thead> 
       <tbody> 

       <tr class="odd"> 

        <td style="width: 40%;"><span style="color: black;">unix_server_read</span></td> 
        <td style="width: 55%;"><span style="color: black;">Role with UNIX based entitlements having read access</span 
></td> 
       </tr><tr style="color:black"></tr><tr style="color:black"> <td colspan="1">End Date: <input style="width:70px" nam 
e="ar_enddate" value="" id="ar_enddate" type="text"><img src="images/icons/fugue/calendar-month.png" height="16" width="16"></td>< 
/tr><tr style="height:8px"></tr><tr class="even"> 

        <td style="width: 40%;"><span style="color: black;">unix_server_write</span></td> 
        <td style="width: 55%;"><span style="color: black;">Role with UNIX based entitlements having write access</spa 
n></td> 
       </tr><tr style="color:black"></tr><tr style="color:black"> <td colspan="1">End Date: <input style="width:70px" nam 
e="ar_enddate" value="" id="ar_enddate" type="text"><img src="images/icons/fugue/calendar-month.png" height="16" width="16"></td>< 
/tr><tr style="height:8px"></tr></tbody> 
+0

等等......什麼? – dbrin

+0

你從哪裏得到這些錯誤?請粘貼完整的錯誤消息,堆棧跟蹤和'nextpage'控制器動作的主體。 – socha23

回答

0

不通過HTML回服務器。相反,請提取相關參數(使用<g:form>)並在AJAX調用中重新渲染文件的內容。

您可以通過將您的table的內容提取爲grails-template file來實現此目的。通過這種方式,您可以在AJAX調用中呈現表格的內容。

在你的主GSP文件,您的表看起來像:

<table> 
    <g:render template="yourTableContent" model="${[..]}" />  
</table> 

與位於同一位置的_yourTableContent.gsp文件作爲GSP位於

在你的行動從客戶端調用您可以撥打:

def nextpage = { 
    [..] 
    render(template:"yourTemplateContent", model: [...]) 
} 
+0

換句話說,我是否需要將我的表格轉移到模板gsp並將其呈現在main.gsp和next.gsp上,我如何處理模型或內容,並非完全清晰 –

+0

我需要的所有字段都應位於內部標記? –

+0

我不確定你有哪種輸入元素..暫時只是根本不使用模型。你可以使用它來傳遞一些信息(比如輸入的用戶名或輸入的過濾器)。 – Chris

相關問題