Ajax响应没有更新特定的List codeigniter?

时间:2017-03-17 04:36:38

标签: php ajax codeigniter

当我将我的列表更新到数据库时,它的运行正常,ajax请求也会返回,但我的列表没有更新。

View.php:      

            <li class="fileLiContent" id="fileLi<?php echo $row['lpf_id'];?>" data-fileid="<?php echo $row['lpf_id'];?>">
                <div class="checkbox edit<?php echo $row['lpf_id'];?>">
                    <label class="no-padd">
                        <input type="checkbox" class="checkboxClass" value="">
                        <span class="cr"><i class="cr-icon glyphicon glyphicon-ok"></i></span>
                        <span class="title"><?php echo $row['lpf_name'];?> <a href="#" class="gap-ml-25" onclick="editId(<?php echo $row['lpf_id']; ?>);">edit</a></span>
                    </label>
                </div>

                <div class="editText<?php echo $row['lpf_id'];?>" style="display: none;">
                    <input type="text" name="file_name" class="my-app-input in-default textbox<?php echo $row['lpf_id'];?>" placeholder="Type file name" value="<?php echo $row['lpf_name'];?>">
                    <a href="#" class="btn my-btn btn-blue" style="margin-right: 5px;" onclick="updateId(<?php echo $row['lpf_id']; ?>);">Update</a>
                    <a href="#" class="btn my-btn btn-blue" style="margin-right: 5px;" onclick="cancelId(<?php echo $row['lpf_id']; ?>);">Cancel</a>
                    <?php $this->load->view('petition/dateMultipleUpload',$row); ?>
                </div>

                <span class="details ml"><?php echo date("m/d/Y", strtotime($row['lpf_created_date']));?></span>
                <br>

                <span class="details ml"><?php echo basename($row['lpf_path']) ;?></span>

                <br>

                <?php if($row['lpf_expiry_date'] != '0000-00-00 00:00:00') :?>
                    <span class="details ml" style="font-weight: bold;">Expiry date:&nbsp;&nbsp;</span><?php echo date("m/d/Y", strtotime($row['lpf_expiry_date']));?>
                    <br>
                <?php endif ;?>

                <?php if($row['lpf_due_date'] != '0000-00-00 00:00:00') :?>
                    <span class="details ml" style="font-weight: bold;">Due date:&nbsp;&nbsp;</span><?php echo date("m/d/Y", strtotime($row['lpf_due_date']));?>
                    <br>
                <?php endif ;?>

                <?php if($row['lpf_approval_date'] != '0000-00-00 00:00:00') :?>
                    <span class="details ml" style="font-weight: bold;">Approval date:&nbsp;&nbsp;</span><?php echo date("m/d/Y", strtotime($row['lpf_approval_date']));?>
                    <br>
                <?php endif ;?>

                <?php if($row['lpf_remainder_date'] != '0000-00-00 00:00:00') :?>
                    <span class="details ml" style="font-weight: bold;">Reminder date:&nbsp;&nbsp;</span><?php echo date("m/d/Y", strtotime($row['lpf_remainder_date']));?>
                    <br>
                <?php endif ;?>

                <?php if($row['lpf_note'] != "") :?>
                    <span class="details ml" style="font-weight: bold;">Notes:&nbsp;&nbsp;</span><?php echo $row['lpf_note'];?>
                    <br>
                <?php endif ;?>

Model.php

public function getPetionFile()
{
    $query = $this->db->query("SELECT * FROM lpd_petition_files WHERE lpf_id = 147 ");
    return $query->row();
}

Controller.php我将获得特定的列表细节

public function performUpdateDocumentName(){
  $data = $this->petition_model->getPetionFile();
  echo json_encode($data);}

Ajax:尝试更新特定列表

function updateId(id) {

var filename =$('.textbox'+id).val();  
var expirydate = $('.expiryDateHV'+id).val(); 
var duedate = $('.dueDateHV'+id).val(); 
var reminder = $('.reminderHV'+id).val(); 
var note = $('.noteValue'+id).val(); 

$.ajax({
    url: "<?php echo base_url('Petition_controller/performUpdateDocumentName/'); ?>"+id,
    type: 'POST',
    dataType : 'json',
    data: { 'filename': filename, 'expirydate' : expirydate, 'duedate' : duedate, 'reminder' : reminder, 'note' : note },
    error: function(reponse) {
            },
    success: function(reponse){

        $(".editText"+id).hide();
        $('.edit'+id).show();

        $('#fileLi'+id).html(reponse); 
    }
}); }

1 个答案:

答案 0 :(得分:0)

Controller.php这样

      $update = $this->model->updateFiles($uploadData);

  $statusMsg = $update?'success':'error';

  if ($statusMsg == 'success') {
    $data['row'] = $this->petition_model->getPetionFile($id);
    $theHTMLResponse = $this->load->view('UploadedFilesList.php', $data, true);

    echo json_encode(array('success'=>'success', 'dataa'=> $theHTMLResponse));
  }else{
    echo json_encode(array('error'=>'Something went wrong, please try again.'));
  }

的Ajax:

function updateId(id) {

var filename =$('.textbox'+id).val();  
var expirydate = $('.expiryDateHV'+id).val(); 
var duedate = $('.dueDateHV'+id).val(); 
var reminder = $('.reminderHV'+id).val(); 
var note = $('.noteValue'+id).val(); 

$.ajax({
    url: "<?php echo base_url('petitions/perform/updateDocumentName/'); ?>"+id,
    type: 'POST',
    dataType : 'json',
    data: { 'filename': filename, 'expirydate' : expirydate, 'duedate' : duedate, 'reminder' : reminder, 'note' : note },
    error: function(response) {
        alert('Something went wrong, please try again.');
            },
    success: function(response){

        if(response.success == 'success'){
            alert('File updated successfully.');
            $('#filesList #updateUI'+id).html(response.dataa); 

        }else{
            alert('Something went wrong, please try again.');
        }
        $(".editText"+id).hide();
        $('.edit'+id).show();

    }
}); }