2013-02-20 77 views
6

大家好,我需要一些關於ajax加載方法的幫助。基本上我需要使用Ajax load()在用戶檢查單選按鈕後在主頁面中顯示一個jsp。我附上了需要顯示jsp的頁面圖像以及我的jsp代碼..請幫助! web page使用AJAX加載方法加載jsp頁面

<div id="verification"> 
    <p align=center class="4f1_title" ><u>Verification Decision</u></p> 
    <table border="0" cellpadding="0" cellspacing="0" align=center 
width="100%"> 
<tbody> 

    <tr> 
     <td width="10%"></td> 
     <td width="8%">Passed <input id="passed" type="radio" 
      value="P" onclick="()"></td> 
     <td colspan="2" width="8%">Pending <input id="pending" 
      type="radio" value="H" onclick="()"></td> 
     <td width="9%">True Hit <input id="failed" type="radio" 
      value="F" onclick="()" disabled></td> 
     <td width="13%">Parcel Returned <input id="returned" 
      type="radio" value="S" onclick="()"></td> 
     <td width="23%">Referred to Law Enforcement <input id="law" 
      type="radio" value="L" onclick="()"></td> 
     <td width="8%">Retired <input id="retired" type="radio" 
      value="R" onclick="()" disabled></td> 
       <td width="12%">Return Reason <input id="ac" 
       type="radio" value="C" onclick="()"></td> 
     <td width="10%"></td> 
    </tr> 
     </tbody> 
      </table> 
     </div> 
      <br> 

        <div align=center> 
       <a href="javascript:handleClick()"><u> 
       <div id='showhidecomment'>Show Comments</div></u></a> 
       <div id='chkcomments'> 
       </div> 
    </div> 
    <br> 
+0

這些都是'onclick =「()」'?你有什麼嘗試?你看過jQuery的['.load()'方法](http://api.jquery.com/load/)嗎? – 2013-02-20 18:36:13

+0

對不起,混亂..我試圖使用一個處理程序來做到這一點,但我不能再去那個潰敗了,我會刪除它..到目前爲止,我試過這個,但它不工作.. $(document).ready(function (){('#verification')。find('#passed'){ $(「radio」)。click(function(){(「#showhidecomment」)。load(「sample.jsp」 ); { } }); – Fahad 2013-02-20 18:55:02

回答

6

嘗試

$(function() { // when DOM is ready 
    $("#showhidecomment").click(function(){ // when #showhidecomment is clicked 
     $("#chkcomments").load("sample.jsp"); // load the sample.jsp page in the #chkcomments element 
    }); 
}); 

,改變你的HTML(鏈接部分)到

<div> 
    <div id='showhidecomment'>Show Comments</div> 
    <div id='chkcomments'></div> 
</div> 

由於div元素在a元素內無效。


更新發表評論

我想自定義data-url屬性添加到這些元素(到指定頁面加載

<input id="passed" type="radio" value="P" data-url="some-page.jsp" /> 
<input id="law" type="radio" value="L" data-url="some-other-page.jsp" /> 
<input id="ac" type="radio" value="C" data-url="some-third-page.jsp" /> 

,然後申請一個給他們的句柄

$('#verification').on('change','input[type="radio"][data-url]', function(){ 
    if (this.checked){ 
     var url = $(this).data('url'); 
     $("#chkcomments").load(url); 
    } 
}); 
+0

Thanks @Gaby aka G.Petrioli,但是,當用戶選擇單選按鈕而不是'showhidecomment'鏈接時,應該調用這個函數。 – Fahad 2013-02-26 17:21:45

+0

@法哈德,哪個單選按鈕?(*你有很多*) – 2013-02-26 18:26:32

+0

aka G.Petrioli,通過,執法和退貨原因。所有三個加載不同的頁面 – Fahad 2013-02-26 18:31:49

2

如果你只是想AJAX加載,你可以使用jQuery的負載頁:http://api.jquery.com/load/

還有jquery的得到:http://api.jquery.com/jQuery.get/

您可以找到文檔中一個簡單的例子。

更新:

您可能需要添加一個引用了jQuery庫,如果你還沒有準備好。請參閱下面的示例代碼。

簡單的頁面顯示 '世界你好':http://jsbin.com/ivinuw/1/

頁與按鈕。當你點擊按鈕,它使用jQuery的負載AJAX加載頁面上方爲一個div容器: http://jsbin.com/ubitat/1/edit