2010-03-18 66 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。