【问题标题】:jQuery Mobile Page - Something wrong with structure - does not fire $.ajaxjQuery Mobile 页面 - 结构有问题 - 不会触发 $.ajax
【发布时间】:2012-08-09 14:51:57
【问题描述】:

有一些涉及的代码。该页面列出了团队成员提交的休假申请,并允许经理批准或拒绝申请。页面的流程是:

  1. 在 pageshow 中调用 getLeaveDetails()
  2. getLeaveDetails() 使用 $.ajax 调用 /webservices/getPendingLeaveApps.ashx
  3. 成功后,会调用 showForm(data, textStatus, jqXHR) - 这很好用
  4. showForm 在 a 内创建标记 - 这很好用
  5. 在运行时创建的标记包括按钮 - 这很好用
  6. “approve”和“reject”两个按钮分别调用它们各自的函数approveLeave(iID) 和rejectLeave(iID) - 当然通过ID 来批准或拒绝 - 这也有效
  7. approveLeave(iID) 和 rejectLeave(iID) 依次使用 $.ajax 调用 .ASHX 页面,将 ID 作为参数传递给 ASHX 处理操作 - 在页面上选择批准或拒绝 -这不起作用

我做错了什么?或者有没有人可以提出更好的结构?非常非常欢迎任何帮助。完全没有 JS 和 HTML 方面的经验。

非常感谢

最好的祝福

<div data-role="page"  id="pLeave" data-add-back-btn="true"  data-back-btn-text="Home">
<script type="text/javascript">
    $('#pLeave').live('pageshow', function () {
        getLeaveDetails() ;
    }) ;

    function getLeaveDetails() {
        $.ajax({
            type: 'POST',
            data: {numRows: 10},
            url: '/webservices/getPendingLeaveApps.ashx', 
            success: function(data, textStatus, jqXHR) {
                showForm(data, textStatus, jqXHR) ;
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert('error' + textStatus + ' ' + errorThrown + ' ' + jqXHR.status + ' ' + jqXHR.statusText + ' ' + jqXHR.data + ' ' + jqXHR.responseText);
                //$("#result_labels").append('<p> textStatus ' + textStatus + '</p>') ;
            }
        });
    }

    function showForm(data, textStatus, jqXHR) {
        $("#resultsArea").html("") ;
        var h = '' ;
        for (i = 0; i < data.length; i++) {
            h = h + '<ul data-role="listview" data-inset="true">' ;
            h = h + '<li>' ;
            h = h + '<p><strong>' + data[i].empName + '</strong></p>' ;
            h = h + '<p><strong>'  + data[i].designation +'</strong></p>' ;
            h = h + '<p><strong> Applied for ' + data[i].noOfDays + ' days of ' + data[i].category + ' leave' ;
            h = h + '<p><strong> From ' + data[i].startDate + ' To ' + data[i].endDate + '</strong></p>' ;
            h = h + '<input type="button" value="Approve" data-inline="true" onclick="approveLeave(' + data[i].id + ');" />' ;
            h = h + '<input type="button" value="Reject" data-inline="true"  onclick="rejectLeave(' + data[i].id + ');" />' ;
            h = h + '</li></ul>' ;
        }
        $("#resultsArea").html(h) ;
        $("#resultsArea").trigger("create");
    }
    function approveLeave(iID) {
        $.ajax({
            type: 'POST',
            data: {id: iID, action: "A"},
            url: '/webservices/mob_processLeave.ashx', 
            success: function(data, textStatus, jqXHR) {
                //showForm(data, textStatus, jqXHR) ;
                getLeaveDetails() ;
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert('error' + textStatus + ' ' + errorThrown + ' ' + jqXHR.status + ' ' + jqXHR.statusText + ' ' + jqXHR.data + ' ' + jqXHR.responseText);
                getLeaveDetails() ;
            }
        });
    }
    function rejectLeave(iID) {
        $.ajax({
            type: 'POST',
            data: {id: iID, action: "R"},
            url: '/webservices/mob_processLeave.ashx', 
            success: function(data, textStatus, jqXHR) {
                //showForm(data, textStatus, jqXHR) ;
                getLeaveDetails() ;
            },
            error: function(jqXHR, textStatus, errorThrown) {
                alert('error' + textStatus + ' ' + errorThrown + ' ' + jqXHR.status + ' ' + jqXHR.statusText + ' ' + jqXHR.data + ' ' + jqXHR.responseText);
                getLeaveDetails() ;
            }
        });
    }
</script>
<div data-role="header">
    <h1>Leave Apps</h1>
</div><!-- /header -->
<div data-role="content">   
    <div class="content-primary">
        <div id="resultsArea">
        </div>
    </div>
</div><!-- /content -->

【问题讨论】:

    标签: jquery ajax mobile


    【解决方案1】:

    它现在正在工作 - 真的,非常愚蠢的错误 - 很抱歉向这个最有用的组发送垃圾邮件。 传递给 mob_processLeave.ashx 的参数错误。在开始编码和标准化参数之前写下所有内容的另一个合适的例子。应该传递“approve”而不是“A”作为第二个参数。

    data: {id: iID, action: "approve"},
    url: '/webservices/mob_processLeave.ashx',
    

    不过,希望代码 sn-p 对某人有所帮助。

    最好的祝福

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-28
      • 1970-01-01
      • 2011-09-02
      相关资源
      最近更新 更多