导航页面后不显示数据

时间:2012-06-11 05:58:59

标签: ajax jquery-mobile

我有问题。我有一个调查表,在这种形式我也使用ajax来调用一些数据。当用户单击取消时,我希望它导航到其他页面,在该页面中使用ajax显示listview中的数据列表。对于点击和导航部分,我已成功将其带到我想要的页面,但问题是,它不再显示数据列表。我使用了与其他页面相同的方式,但为此,我无法获得帮助?我已多次浏览过我的代码,但我无法得到错误的内容。这是我的页面调查表的代码:

$('#MrateCourse').live('pageinit', function(){

    var rowInput = "1";
    var pageInput = "1";
    var idInput = "${courseId}";
    var regNoInput = "${regNo}";

    $.ajax({
        url: '${pageContext.request.contextPath}/getRegisteredClassesDetails.html',
        data: ( {rows: rowInput, page: pageInput, courseId: idInput, regNo: regNoInput}),
        type: 'POST',
        success: function(json_results){
            $('#list').append('<ul></ul>');
            listItems = $('#list').find('ul');
            $.each(json_results.rows, function(courseId) {
            html  = ' Course Name    :  
                    + '<b>' + json_results.rows[courseId].courseName + '</b>';
            html += '</br> Registered Person :  
                    + '<b>' + json_results.rows[courseId].fullName + '</b>';

            listItems.append(html);
            });

            $('#list ul').listview();
         }
    }); 
});

$(function() {
    var currentTime = new Date();
    var month = currentTime.getMonth() + 1;
    var day = currentTime.getDate();
    var year = currentTime.getFullYear();

    if(day<10){
        day='0'+day;
    } 
    if(month<10){
        month='0'+month;
    } 

    var currentTime = new Date();
    var hours = currentTime.getHours();
    var minutes = currentTime.getMinutes();

    var suffix = "AM";
    if (hours >= 12) {
    suffix = "PM";
    hours = hours - 12;
    }
    if (hours == 0) {
    hours = 12;
    }

    if (minutes < 10)
    minutes = "0" + minutes;

    $('#dateTime').html("<b>" + month + "/" + day + "/" + year + "  " + hours + ":" + minutes + " " + suffix + "</b>");
});


    <form id="" action="${pageContext.request.contextPath}/MRegisteredClasses.phone" method="POST">
    <table>
            <tr>
                <td>Date: 
                    <span id="dateTime"></span><br/></td>
            </tr>
            <tr>
                <td>Company:</td>
                <td><input type="text" value=""/><br/></td>
            </tr>
            <tr>
                <td><b>Based on your experience in this course, please answer<br>the following questions:
                <br>1 = Strongly Disagree, 5 = Strongly Agree</b></td>
            </tr>
            <tr>
                <td>The web-based training media used was of high quality.</td>
                <td><select>
                        <option value=""></option>
                        <option value="5">5</option>
                        <option value="5">4</option>
                        <option value="3">3</option>
                        <option value="2">2</option>
                        <option value="1">1</option>
                    </select><br/></td>
            </tr>
            <tr>
                <td>I had enough time to learn the subject matter covered in the course.</td>
                <td><select>
                        <option value=""></option>
                        <option value="5">5</option>
                        <option value="5">4</option>
                        <option value="3">3</option>
                        <option value="2">2</option>
                        <option value="1">1</option>
                    </select><br/></td>
            </tr>
            <tr>
                <td>My knowledge and/or skills increased as a result of this course.</td>
                <td><select>
                        <option value=""></option>
                        <option value="5">5</option>
                        <option value="5">4</option>
                        <option value="3">3</option>
                        <option value="2">2</option>
                        <option value="1">1</option>
                    </select><br/></td>
            </tr>
            <tr>
                <td>Additional comments or ideas to improve this course:</td>
            </tr>
            <tr>
                <td><textarea rows="3" ></textarea></td>
            </tr>
            <tr>
                <td>What additional topics would you like to see addressed in a future online course?</td>
            </tr>
            <tr>
                <td><textarea rows="3"></textarea></td>
            </tr>
            <tr>
                <td align="left">
                    <input type="submit" data-inline="true" id="submit" value="Submit This Survey" class="ui-btn-right"
                        onClick="confirm( 'Thanks for filling the survey' )"/>
                    <a href="${pageContext.request.contextPath}/MRegisteredClasses.phone" class="ui-btn-right"
                        data-role="button" data-inline="true">Cancel</a>
                </td>
            </tr>
    </table>
    </form>

这是我需要导航的页面的代码。

<div data-role="page" id="MregisteredClasses">
<div data-role="content">
    <h3>Courses Name</h3>
    <p id="note">*Click at the courses to view the details</p>
    <h1></h1>
    <div id="courseName"> 
        <ul data-role="listview" data-inset="true" id="list"></ul>
        <script type="text/javascript">
            $('#MregisteredClasses').on('pageinit', function(){
                var rowInput = "1";
                var pageInput = "1";

                $.ajax({
                 url: '${pageContext.request.contextPath}/getRegisteredClassesData.html',
                 data: ( {rows : rowInput , page : pageInput}),
                 type: 'POST',

                success: function(json_results){
                    $('#list').append('<ul data-role="listview" data-inset="true" data-split-icon="gear"</ul>');
                    listItems = $('#list').find('ul');
                    $.each(json_results.rows, function(key) {
                      html = '<li <h3><a href="${pageContext.request.contextPath}/MRegisteredClassesDetail.phone?courseId=' 
                             + [json_results.rows[key].courseId] + '&regNo=' + [json_results.rows[key].regNo] +
                             '"rel="external">' + json_results.rows[key].courseName+ '</a></h3>'
                             + '<a href="${pageContext.request.contextPath}/MRateCourse.phone?courseId=' 
                             + [json_results.rows[key].courseId] + '&regNo=' + [json_results.rows[key].regNo] + 
                             '"rel="external">RATE THIS COURSE</a>';
                    listItems.append(html); 
                    });

                $('#list ul').listview(); 
                },
            });
            });
        </script>
    </div> 
</div><!-- /content -->

1 个答案:

答案 0 :(得分:0)

我已经知道了......我将data-ajax="false"添加到我的表单中。