2010-03-18 67 views
1

我試圖使用JQTouch將數據庫驅動的多選式風格的學習網站(用JSP編寫)轉換爲iPhone應用程序。在JQTouch中使用動畫加載獨立頁面

如果我都將q &由於加載到自己的div在同一文件中,我可以很容易地聯繫起來,並使用鏈接到主題標籤,就像他們之間的動畫:一類=「按鈕的」 href =「#question22」

不幸的是,這是不實際的。目前網站的邏輯需要調用一些動態生成的頁面;我不能在同一個平面文件中將每個問題都包含在它自己的div中。

我會如何動態(預)加載下一個問題(一個像AskQuestion.jsp?questionId = Kzhctand的JSP頁面),然後在用戶按下按鈕後在應用程序中提供該問題?

感謝您提供的任何幫助。

-Donovan

回答

2

我爲我的閃存卡系統做了類似的事情。 我有一個div用於當前卡的「前」和「後」,當用戶給出答案時,它通過ajax,json和php的魔法加載下一張卡片。

以下是答案頁的相關部分。

<h2>Answer:</h2> 
<div class="qna"> 
    <p id="question2" class="qna">SomethingsNotWorking.</p> 
    <p id="answer2" class="qna">SomethingsNotWorking.</p> 
</div> 
<h2>Did you know it?</h2> 
<a >Submit</a> 
<BR><a href="#" onClick="javascript:sendCardInfo('Yes')" name="knewIt">Yes</a> 
<BR><a href="#" onClick="javascript:sendCardInfo('No')" name="knewIt">No</a> 

這是通過發送ajax查詢來處理用戶響應的函數。

function sendCardInfo(str){ 
    //alert("sendCardInfo " + str); 
    $.ajax({ 
     type: "POST", 
     url: "ajax.php", 
     data: "currentCard="+$(document).data('currentCard')+"&currentDeck="+$(document).data('currentDeck')+"&knewIt="+str, 
     dataType: "json", 
     success: function(data){ 
      jQT.goTo('#home', 'swap'); 
      // store the json response in the data object so it can be retrieved later. 
      $(document).data("currentCard" , data.currentCard); 
      $(document).data("currentDeck" , data.currentDeck); 
      $(document).data("question" , data.question); 
      $(document).data("answer" , data.answer); 

      // update the q and a divs with the current questions. 
      $('#question1').html($(document).data("question")); 
      $('#question2').html($(document).data("question")); 
      $('#answer2').html($(document).data("answer")); 
     }, 
    }); 
} 

在後端我有一個名爲ajax.php的PHP頁面生成下一張卡片爲JSON。