2017-08-22 4 views
-4

私はこの問題を3週間解決するのに苦労していますが、私はmysqlクエリによってデータが取り込まれたhtmlテーブルを持っています。 jquery ajax postメソッドは、ページの最初の読み込み中に問題はありません、私はすべての一意のIDを取得し、ブートストラップモーダルを介してそれを検証することができますが、問題は最初のポストメソッドの後に、すべての一意のIDは最初に投稿されたIDで変換されます。すべてのデータはそのIDを基にしていますので、その方法ではいけません。誰かが誰にでも不具合がどこにあるのか助けてくれる?ここ Ajaxポストリクエストの後にJqueryが一意のIDを取得しない

はここ

モーダル

$('a[data-stateName]').on('click', function(){ 
var ID = ""; 
ID = $(this).attr("data-stateName"); 
//console.log(ID); 

$('#modalIndividualDepartment').on('show.bs.modal', function() { 
//var cashAdvanceCredit = $("#cashAdvanceCredit").attr("value"); 
//console.log(cashAdvanceCredit); 
       $.getJSON('JSON/resultsCashIssuanceDepartment.json', 
function(data){ 


       //var ID = checkID; 

       var output = '<table class="table table-bordered table- 
           condensed"><tr>'; 
       output +='<th id="highlight"><font color="white"> 
          <center>Employee ID</center></font></th><th 
          id="highlight"><font 
          color="white"><center>Name</center></font></th> 
          </tr>'; 
       output += '<tr>'; 
          $.each(data, function(key, val){ 
          if(val.id == ID){ 
       output += '<td><center>' + idier(val.id)+val.id + 
          '</center></td>'; 
       output += '<td><center>' + val.name + '</center></td>'; 
          var department = val.department; 
          var dateCovered = val.dateCovered; 
          var explodeDateCovered = dateCovered.split("to"); 
          var name = val.name; 
          var duration = val.duration; 
          var fromStart = explodeDateCovered[0]; 
          var toEnd = explodeDateCovered[1]; 
          var cashAdvanceCredit = val.cashAdvanceCredit; 


       output += '</tr></table>'; 
       output += '<form method="post" 
          id="formSubmitDepartmentIndividual"><div 
          class="form-group row"><div 
          class="col-xs-3"></div><div class="col-xs-6"> 
          <input type="text" 
          name="cashAdvanceDepartmentOneTimeModal" 
          id="cashAdvanceModalDepartment" 
          class="form-control" placeholder = "less than '+ 
          cashAdvanceCredit +'"> 
          </div></div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="date" 
          name="datecashAdvanceAllOneTimeModal" 
          id="modalDepartmentDate" class="form- 
          control" value = "'+today+'" readonly></div> 
          </div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="function" 
          class="form-control" value = "" ></div></div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="employeeID" 
          class="form-control" value = "'+ ID +'" ></div> 
          </div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="type" 
          class="form-control" value = 
          "cashAdvanceIndivualDepartment" ></div></div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="department" 
          class="form-control" value = "'+department+'" > 
          </div></div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="fromStart" 
          class="form-control" value = "'+fromStart+'" > 
          </div></div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="toEnd" 
          class="form-control" value = "'+toEnd+'" ></div> 
          </div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="name" 
          class="form-control" value = "'+name+'" ></div> 
          </div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><input 
          type="hidden" name="duration" 
          class="form-control" value = "'+duration+'" > 
          </div></div>'; 
       output += '<div class="form-group row"><div class="col- 
          xs-3"></div><div class="col-xs-6"><button 
          type="button" class="btn btn- 
          default" data- 
          dismiss="modal">Close</button>&nbsp<input 
          type="submit" 
          value="submit" 
          id="submitModalDepartmentIndividual" 
          name="btnSubmit" 
          class="btn btn-primary"></div></div></form>'; 

        var x = cashAdvanceCredit; 
        $('#dataOnDepartment').html(output); 
        var value = $('#cashAdvanceModalDepartment').val(); 
        console.log(value); 
        //disable submit button if cash advance is empty 
        $('#submitModalDepartmentIndividual').prop("disabled", 
        true); 
        $('#cashAdvanceModalDepartment').keyup(function(event){ 
        var input = $('#cashAdvanceModalDepartment').val(); 
        var Exp = new RegExp(input); 

        if(event.which != 8 && 
        isNaN(String.fromCharCode(event.which))){ 

        $('#submitModalDepartmentIndividual').prop("disabled", 
        true); 
        }else if(($('#cashAdvanceModalDepartment').val() == '') 
        || (Number($('#cashAdvanceModalDepartment').val()) > 
        Number(cashAdvanceCredit)) || 

       (/^\s*$/.test($('#cashAdvanceModalDepartment').val().trim()))) 
     { 


      $('#submitModalDepartmentIndividual').prop("disabled", true); 
         } 
        else 
     if(($("#cashAdvanceModalDepartment").val().replace(/ /g,'').length 
     != 0)){ 


       $('#submitModalDepartmentIndividual').prop("disabled",false); 

        } 
        else{ 

     $('#submitModalDepartmentIndividual').prop("disabled",false); 
        } 
        console.log(cashAdvanceCredit); 
        console.log($('#cashAdvanceModalDepartment').val()); 
        }); 

        } 
       }); 
       //marker 

     $('#formSubmitDepartmentIndividual').on('submit',function(event){ 
        event.preventDefault(); 
        $.ajax({ 
          url:"ajaxPaymentProcessor.php", 
          method:"POST", 

     data:$('#formSubmitDepartmentIndividual').serialize(), 
          success: function(data){ 
          //$('#modalIndividualDepartment').hide(); 
          $('#formSubmitDepartmentIndividual')[0].reset(); 

     $('#modalIndividualDepartment').modal('hide'); 
           $('#tableDepartment').html(data); 
           //$(".objects-list").html(data["html"]); 
          } 
         }); 

        });  

      }); 

      }); 
      }); 
上のデータを処理するためのJavaScriptここ
<div class="modal fade" id="modalIndividualDepartment" tabindex="-1" 
role="dialog"> 
<div class="modal-dialog" role="document"> 
<div class="modal-content"> 
    <div class="modal-header"> 
    <button type="button" class="close" data-dismiss="modal" aria- 
label="Close"><span aria-hidden="true">&times;</span></button> 
    <h4 class="modal-title">Individual Payment</h4> 
    </div> 
    <div class="modal-body" id="dataOnDepartment"> 

    </div> 
    <div class="modal-footer"> 



     </div> 
    </div> 
    </div> 
</div> 

検証

のためのモーダル私のHTMLテーブルここ

$cashAdvances = array(); $x = 0; 
    $department = $_POST['department']; 
    $fromStart = $_POST['fromStartDepartment']; 
    $toEnd = $_POST['toEndDepartment']; 

<div id="tableDepartment"> 

    <table class="table table-bordered table-condensed" id="<?= 
    'departmentTable'; ?>" > 
    <tr bgcolor = "#2c3e50"> 
      <th><font color="white"> Company Id</th> 
      <th><font color="white">Department</th> 
      <th><font color="white">Name</th> 
      <th><font color="white">Date Covered</th> 
      <th><font color="white">Cash Advance</th> 
      </tr> 
     <?php $data = array(); 
       $dateCovered = $fromStart.'to'.$toEnd; 
      ?> 
      <?php while($result = 
      mysqli_fetch_array($resultQueryDepartment)): ?> 




       <?php $cashAdvances[] += $result['company_id']; 
        $data[] = array('id'=> $result['company_id'], 
            'department'=>$result['department'], 
            'name'=>$result['name'], 
            'dateCovered' =>$dateCovered, 
         'cashAdvanceCredit' => 
      $resultAttendancePayroll['salary'], 
         'duration' => 'Weekly' 

        ); 
        $json_data = json_encode($data); 
        $myDir = 'JSON'; 

        if(!file_exists($myDir)){ 
         $oldmask = umask(0);//helpful when used in linux 
         mkdir($myDir, 0777); 
        } 



     file_put_contents($myDir.'/resultsCashIssuanceDepartment.json', 
     $json_data); 
      ?> 
    <?php while($result = mysqli_fetch_array($resultQueryDepartment)): ?> 
    <tr></tr> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td></td> 
    <td> 
    <a data-stateName="<?= $result['company_id']; ?>" id="susubukan"><button 
    type="button" id="modalIndividualOnDepartment" value="<?= 
    $result['company_id']; ?>" class="btn btn-primary edit_data" data- 
    toggle="modal" data-target="#modalIndividualDepartment" 
       <?php 
       if(($resultCashAdvanceByIndividualOnDepartment) || 
    ($resultFullyPaidIndividualOnDepartment == '0')){ 
        echo 'disabled'; 
       }else{ 
        echo ''; 
       } 
        ?> 
       >Click to Pay Cash Advance</button></a> 
    </td></tr> 
<?php endwhile; ?> 
</table> 
</div> 

のコードされていますajaxコールを処理するランディングページです

$type= $_POST['type']; 
$cashAdvances = array(); $x = 0; 
$employeeID = $_POST['employeeID']; 
$prettyEmployeeID = idier($_POST['employeeID']).$_POST['employeeID']; 
$duration = $_POST['duration']; 

<?php if($type == 'cashAdvanceIndivualDepartment'): ?> 

      <?php 
      //scope variable 
      $date = $_POST['datecashAdvanceAllOneTimeModal']; 

      $department = $_POST['department']; 
      $name = $_POST['name']; 
      $fromStart = $_POST['fromStart']; 
      $toEnd = $_POST['toEnd']; 

      $cashAdvanceCredit = 
$_POST['cashAdvanceDepartmentOneTimeModal']; 
      //------end scope variable------// 



      if($queryCashAdvanceResult){ 

      $output = '<h4><center>Cash Advance of <b><font 
         color="red">'.$cashAdvance.' PHP</font></b> was made 
         for <b><font color="red">'.$employee['first_name'].' 
        '.$employee['last_name'].'</font></b></center> </h4>'; 
      $output .= '<table class="table table-bordered table-condensed" 
         id="departmentTable"> 
         <tr bgcolor = "#2c3e50"> 
         <th><font color="white"> Company Id</th> 
         <th><font color="white">Department</th> 
         <th><font color="white">Name</th> 
         <th><font color="white">Date Covered</th> 
         <th><font color="white">Cash Advance</th> 
         </tr>'; 
      $data = array(); 




      while($result = mysqli_fetch_array($resultQueryDepartment)){ 




       $cashAdvances[] += $result['company_id']; 
       $data[] = array('id'=> $result['company_id'], 
        'department'=>$result['department'], 
        'name'=>$result['name'], 
        'dateCovered' =>$dateCovered, 
        'cashAdvanceCredit' => 
        $resultAttendancePayroll['salary'], 
        'duration' => 'Weekly' 
       ); 
       $json_data = json_encode($data); 
       $myDir = 'JSON'; 

       if(!file_exists($myDir)){ 
        $oldmask = umask(0); // helpful when used in linux 
        server 
        mkdir($myDir, 0777); 
       } 

      file_put_contents($myDir.'/resultsCashIssuanceDepartment.json', 
      $json_data); 



       $output .='<tr> 
          <td><p 
    id="subukanUlit">'.idier($result['company_id']).$result['company_id']. 
       '</p></td> 
        <td>'. $result['department'].'</td> 
        <td>'.$result['name'].'</td> 
        <td>'.prettydate($fromStart)." to 
        ".prettydate($toEnd).'</td> 
         <td> 
         <a data-stateName="'.$result['company_id'].'"> 
       <button type="button" id="modalIndividualOnDepartment" 
       value="'.$result['company_id'].'" class="btn btn-primary 
      edit_data" data-toggle="modal" data- 
      target="#modalIndividualDepartment" 
          '. 
     ((($resultCashAdvanceByIndividualOnDepartment) || 
     ($resultFullyPaidIndividualOnDepartment == 
      '0'))?'disabled':'').'>Click to Pay Cash Advance</button></a> 
          </td> 
       </tr>'; 
       $x++; 
      } 
      $output .='</table></div>'; 
      echo $output; 
      ?> 

      <?php }?> 

      <?php else: ?> 
       <?php if($type == 'cashAdvanceDepartmentOneTime'): ?> 
       <?php 
          $department = $_POST['department']; 
          $duration = $_POST['duration']; 
          $fromStart = $_POST['fromStartDepartment']; 
          $toEnd = $_POST['toEndDepartment']; 
          $cashAdvance = 
          $_POST['cashAdvanceDepartmentOneTime']; 
          $employeeID = $_POST['employeeID']; 
          $employeeID = 
          unserialize(base64_decode($employeeID)); 
          $dateOfPayment = 
     $_POST['dateCashAdvanceDepartment']; 
          $counter = sizeof($employeeID) - 1; 
          $starter = ''; 
          for($starter = 0 ; $counter >= $starter ; 
      $starter++){ 
           $id = $employeeID[$starter]; 
           $id = idier($employeeID[$starter]).$id; 
           $idNotProcessed = $employeeID[$starter]; 
           //select from employee_profile 
           $queryName = "SELECT * FROM 
     employee_profile WHERE company_id = '$idNotProcessed' ORDER BY 
               id DESC LIMIT 1"; 
           $resulQueryName = $db->query($queryName); 
           $resultName = 
     mysqli_fetch_array($resulQueryName); 
           $name = $resultName['first_name']." 
     ".$resultName['last_name']; 
           //end select from employee profile 
           //select department 
            $queryDepartmentCashAdvance = "SELECT 
     employee_profile.id, employee_profile.company_id, 
     company_profile.department 
                    FROM 
     employee_profile INNER JOIN company_profile WHERE 
     employee_profile.company_id = company_profile.company_id 
                    AND 
      employee_profile.company_id ='$idNotProcessed' "; 
            $resultQueryDepartmentCashAdvance = $db- 
      >query($queryDepartmentCashAdvance); 
            $resultDepartmentCashAdvance = 
      mysqli_fetch_array($resultQueryDepartmentCashAdvance); 
            $department = 
      $resultDepartmentCashAdvance['department']; 
           //end select department 
           //CHECK FOR EXISTING RECORD 
           $queryExistingRecord = "SELECT * FROM 
      cash_advance WHERE company_id = '$id' AND date >= '$fromStart' 
                 AND date <= 
      '$toEnd'"; 
           $resultExistingRecord = $db- 
      >query($queryExistingRecord); 
           $existingRecord = 
     mysqli_fetch_array($resultExistingRecord); 

           if(empty($existingRecord)){ 
            //INSERT INTO CASH ADVANCE ONE TIME 
            $queryCashAdvanceDepartment = "INSERT 
     INTO cash_advance(company_id, name, department,advance_payment, 
     date, duration) 
            VALUES('$id', '$name', 
     '$department','$cashAdvance', '$dateOfPayment', '$duration')"; 
            $resultQueryCashAdvanceDepartment = 
     $db->query($queryCashAdvanceDepartment); 
            //END INSERT INTO CASH ADVANCE ONE TIME 
           } 
           //END CHECKING FOR EXISTING RECORD 

          } 
          //------query department-------// 
          $queryDepartment = "SELECT 
     attendance_payroll.company_id, attendance_payroll.name, 
     attendance_payroll.date_identifier, company_profile.department 
          FROM attendance_payroll INNER JOIN 
     company_profile ON company_profile.company_id = 
     attendance_payroll.company_id 
          WHERE company_profile.department = 
     '$department' AND attendance_payroll.date_identifier >='$fromStart' 
     AND attendance_payroll.date_identifier <= '$toEnd' 
          GROUP BY attendance_payroll.company_id ORDER BY 
     attendance_payroll.company_id "; 
          $resultQueryDepartment = $db- 
     >query($queryDepartment); 
          //-----end query department----// 
          $output = '<h4><center>Cash Advance of <b><font 
    color="red">'.$cashAdvance.' PHP</font></b> was made for <b><font 
    color="red">ALL</font></b></center> </h4>'; 
          $output .= '<table class="table table-bordered 
    table-condensed" id="departmentTable"> 
     <tr bgcolor = "#2c3e50"> 
      <th><font color="white"> Company Id</th> 
      <th><font color="white">Department</th> 
      <th><font color="white">Name</th> 
      <th><font color="white">Date Covered</th> 
      <th><font color="white">Cash Advance</th> 
      </tr>'; 
          //$data = array(); 
          //$dateCovered = $fromStart.'to'.$toEnd; 

          while($result = 
       mysqli_fetch_array($resultQueryDepartment)){ 
      //check cash advance per individual if already existing 
           $employeeID = 
       idier($result['company_id']).$result['company_id']; 
           $queryCashAdvanceByIndividualOnDepartment = 
      "SELECT * FROM cash_advance WHERE duration = 'Weekly' 
           AND company_id = '$employeeID' AND date >= 
      '$fromStart' 
           AND date <= '$toEnd'"; 

     $resultQueryCashAdvanceByIndividualOnDepartment = $db- 
     >query($queryCashAdvanceByIndividualOnDepartment); 
     $resultCashAdvanceByIndividualOnDepartment = 
     mysqli_fetch_array($resultQueryCashAdvanceByIndividualOnDepartment); 
           //end checking 
    //check if already fully paid and not be qualified for cash advance 
     $queryFullyPaidIndividualOndepartment = "SELECT * FROM 
     attendance_payroll WHERE company_id = '$employeeID' 
           AND date_identifier >='$fromStart' AND 
     date_identifier <='$toEnd' 
           AND payment_status = '1'"; 
           $resultQueryFullyPaidIndividualOnDepartment 
      = $db->query($queryFullyPaidIndividualOndepartment); 
           $resultFullyPaidIndividualOnDepartment = 
      mysqli_num_rows($resultQueryFullyPaidIndividualOnDepartment); 
           //end checking 
           $output .='<tr> 
          <td><p 


id="subukanUlit">'.idier($result['company_id']).$result['company_id'].'</p> 
    </td> 
          <td>'. $result['department'].'</td> 
          <td>'.$result['name'].'</td> 
          <td>'.prettydate($fromStart)." to 
".prettydate($toEnd).'</td> 
          <td> 
          <a data-stateName="'.$result['company_id'].'"> 
    <button type="button" id="modalIndividualOnDepartment" 
    value="'.$result['company_id'].'" class="btn btn-primary edit_data" 
    data-toggle="modal" data-target="#modalIndividualDepartment" 
          '. 
    ((($resultCashAdvanceByIndividualOnDepartment) || 
    ($resultFullyPaidIndividualOnDepartment == '0'))?'disabled':'').'>Click to 
    Pay Cash Advance</button></a> 
          </td> 
       </tr>'; 
           $x++; 
          } 
          $output .='</table></div>'; 
          echo $output; 
          ?> 
           <!-- VALIDITY OF PAY BUTTON FOR ALL --> 
            <?php 
              $queryAttendancePayrollCompare = 
    "SELECT attendance_payroll.id, attendance_payroll.company_id, 
    attendance_payroll.name, company_profile.department 

    FROM attendance_payroll INNER JOIN company_profile WHERE 
    attendance_payroll.company_id = company_profile.company_id 

    AND date_identifier >= '$fromStart' AND date_identifier <= '$toEnd' AND 
    company_profile.department = '$department' 

    GROUP BY attendance_payroll.company_id ORDER BY 
    attendance_payroll.company_id"; 
    $resultAttendancePayrollCompare = $db- 
    >query($queryAttendancePayrollCompare); 

    $resultAttendancePayrollCompareCount = 
    mysqli_num_rows($resultAttendancePayrollCompare); 

    $queryCashAdvanceCompare = "SELECT * FROM cash_advance WHERE duration = 
    'Weekly' AND department = '$department' 
                     AND 
    date >= '$fromStart' AND date <='$toEnd' GROUP BY company_id ORDER BY 
    company_id"; 
              $resultQueryCashAdvanceCompare = 
    $db->query($queryCashAdvanceCompare); 
              $resultCashAdvanceCompareCount = 
    mysqli_num_rows($resultQueryCashAdvanceCompare); 

             ?> 
          <!-- END VALIDITY OF PAYMENT BUTTON FOR ALL --> 
          <?php 

         ?> 
       <?php endif; ?> 

助けてくださいとの回答の人々が見つかりました多くの感謝

+2

なぜあなたは叫んでいますか? – Satpal

+5

コードが多すぎるため、問題を少し絞り込んでください。 –

答えて

0

:)、

私はランディングページ上にも隠されたモーダル機能のすべてを含める必要があるため、それは更新された後、どのようなことを代わりに同じページにもう読まれていなかった、ランディングページのデータ..

ありがとうとにかく:)

関連する問題