2012-08-09 57 views
0

有這一點涉及的代碼。頁面列表留下由團隊成員提交的應用程序,並允許經理批准或拒絕該應用程序。頁面的流程是:

  1. 在pageshow,getLeaveDetails()被調用
  2. getLeaveDetails()調用使用/webservices/getPendingLeaveApps.ashx $就
  3. 成功時,showForm(數據,textStatus, jqXHR)被稱爲 - 這工作正常
  4. showForm創建標記內 - 這工作正常
  5. 在運行時創建的標記包括按鈕 - 這工作正常
  6. 的兩個按鈕「批准」和「拒絕」叫他們respectiv e函數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 --> 

回答

0

現在是工作 - 真的,真的很愚蠢的錯誤 - 抱歉,垃圾郵件這個最有用的組。 錯誤的參數傳遞給mob_processLeave.ashx。在開始編碼和標準化參數之前寫下所有東西的另一個適合的例子。應該通過「批准」而不是「A」作爲第二個參數。

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

希望的代碼片段可以幫助別人,雖然。

艾耶