doulu7174 2018-09-15 11:37
浏览 36

ajax值未显示在模型窗口中

I want to display to open pdf file in model window. But it is not working properly. code is given below

<td class="text-center">
    <button class="btn btn-sm btn-danger 
    deleteUser" data-toggle="modal" data-target="#myModal1" onclick="edit_book1(<?php echo 
         $row['markid'];?>)">
        <i class="fa fa-upload"></i></button>
</td>

AJAX code

function edit_book1(markid) {
    save_method = 'update';
    $('#form1')[0].reset(); // reset form on modals

    //Ajax Load data from ajax
    $.ajax({
                url: "<?php echo site_url('/users/ajax_edit1')?>/" + markid,
                type: "POST",
                dataType: "JSON",
                success: function(data) {
                    console.log(data);
                    alert(data);

                    $('[name="markid1"]').val(data.file_name);

                    $('#modal_form1').modal('show'); // 
                    show bootstrap modal when complete loaded
                    $('.modal- 
                            title ').text('
                            Upload Images '); // 
                            Set title to Bootstrap modal title
                        },
                        error: function(jqXHR,
                            textStatus, errorThrown) {
                            alert('Error get data from 
                                ajax ');
                            }
                        });
            }

Controller

public
function
ajax_edit1($markid) {
    $data = $this - > User_Model -
        >
        getRows($markid);
    echo json_encode($data);

}

model

function getRows($markid = array()) {
    $this - > db - > select('*');
    $this - > db - > from('upload_ins');
    $this - > db - > where('certid', $markid);
    $query = $this - > db - > get();
    return $query - > row();
}

model window

<?php if(!empty($files)){ 
      foreach($files as $frow)
                             {
        print_r($frow);                              
     ?>
<embed src="<?php echo 
     base_url().'uploads/files/'.$frow 
         ['file_name']; ?>" type='application/pdf' frameborder="0" width="100%" height="400px">

I check it in the console the value returned. But no display in the model window. how to solve this?

In the console window I got

{id: "0", regno: "01107402042", appno: "10001", certid: "1", file_name: "9bfe44de3ddb583778d2b641bdb6b79f.pdf", …}
  • 写回答

2条回答 默认 最新

  • dongxu0690 2018-09-15 13:44
    关注

    It looks like your result output is a json object. If it is then you would need to convert it using json_decode() and then access the item.

    $f_row = json_decode($frow, TRUE);
    

    The TRUE parameter of the json_decode() function will return the data as an associative array, you can now access the row data by keys.

    $f_row['file_name'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了
  • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
  • ¥188 需要修改一个工具,懂得汇编的人来。
  • ¥15 livecharts wpf piechart 属性
  • ¥20 数学建模,尽量用matlab回答,论文格式