在 JQTouch 中加载带有动画的单独页面

发布于 2024-08-25 17:44:50 字数 372 浏览 4 评论 0原文

我正在尝试使用 JQTouch 将数据库驱动的多项选择式学习网站(用 JSP 编写)转换为 iPhone 应用程序。

如果我将所有问答加载到同一文件中自己的 div 中,我可以使用主题标签链接轻松地在它们之间进行链接和动画,例如: a class="button" href="#question22"

不幸的是,这不切实际。网站当前工作的逻辑需要调用许多动态生成的页面;我无法将每个问题都包含在同一个平面文件中自己的 div 中。

我将如何动态(预)加载下一个问题(像 AskQuestion.jsp?questionId=Kzhctand 这样的 JSP 页面),然后在用户按下按钮后在应用程序中提供该问题?

感谢您提供的任何帮助。

——多诺万

I'm trying to convert a database-driven multiple-choice-style study website (written in JSP) into an iPhone app using JQTouch.

If I load all of the Q&As into their own divs in the same file I can easily link and animate between them using links to hashtags, like: a class="button" href="#question22"

Unfortunately this isn't practical. The logic of the website as it currently works requires calls to a number of dynamically generated pages; I can't include every question in its own div in the same flat file.

How would I go about dynamically (pre)loading the next question (a JSP page like AskQuestion.jsp?questionId=Kzhctand ) then serving that up within the app after the user presses a button?

Thanks for any help you might offer.

-Donovan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

得不到的就毁灭 2024-09-01 17:44:50

我为我的抽认卡系统做了类似的事情。
我有一个 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')+"¤tDeck="+$(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 形式生成下一张卡片。

I do something similar to this for my flashcard system.
I have a div for the "front" and the "back" of the current card, when the user gives their answer it loads the next card via the magic of ajax, json, and php.

Here is the relevant section of the answer page.

<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>

This is the function that handles the users response by sending an ajax query.

    function sendCardInfo(str){
    //alert("sendCardInfo " + str);  
    $.ajax({
       type: "POST",
       url: "ajax.php",
       data: "currentCard="+$(document).data('currentCard')+"¤tDeck="+$(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" ));
       },
     });
}

On the backend I have a PHP page called ajax.php generate the next card as JSON.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文