Javascript:未捕获的ReferenceError:在HTMLAnchorElement.onclick中未定义Edited_20170329100333

时间:2017-04-01 09:06:25

标签: javascript php jquery ajax

我不知道为什么我会遇到这个错误。&#34; Edited_20170329100333 &#34;是值的图像名称(从数据库获取并显示)。我有画廊放置,当用户选择它应该显示预览。为此,我有ajax响应,其数据类型为json,因为我使用codeignitor从数据库中取出。当我这样做时<img src="<?php echo base_url(); ?>uploads/inspection/'+json_arr[ind]['attachment_saved_name']+'" class="img-responsive"></img>显示适合的小图像,但当我放置{{1时,我的图片变大我不知道为什么?

我从控制器得到一切正确但我不明白为什么javascript给出错误。这是我的代码:

控制器 Gallery.php

<a href="">

查看:的index.php

function inspection_gallery()
    {
        $this->data['navigation_link'] = 'Inspection Gallery';
        $templateId=$this->input->post('gt');
    //  var_dump($templateId);
        $this->data['frominspection'] = $this->template_model->getAllInspections();
        $swt=$this->data['inspection_images']=$this->template_model->getAllInspectionsImages($templateId);

        echo json_encode($swt,true);
    //  $this->load->view('Gallery/index', $this->data);
    }

脚本:

<select class="form-control input-md" onclick="galleryselectetemplate()" id="templategallery" name="template_opt" >
<?php 
if($frominspection ==''){?>
    <option value="">Select...</option>
<?}else{?>
<?php
    foreach($frominspection as $temp){?>
        <option value="<?=$temp->ca_id?>"><?=$temp->name?></option>
  <?php }?>

<?}?>
</select>

<div class="col-xs-12 col-sm-12 col-md-12 img" id="img">
    <?php if($inspection_images !='')
    { foreach($inspection_images as $img){?>
      <a onclick="viewImage('<?php echo $img->attachment_saved_name; ?>')" title="<?php echo $img->attachment_original_name; ?>" href="javascript:;">
        <img src="<?php echo base_url();?>uploads/inspection/<?php echo $img->attachment_saved_name; ?>" alt="<?php echo $img->attachment_original_name; ?>" width="300" height="200" class="img-responsive"></img>
      </a>
      <div class="desc"><?php echo $img->attachment_name.' ('.$img->column_name.')'; ?></div>

    <?php }} ?>
    </div>

控制台出错:

<script>
  function galleryselectetemplate()
{
    var c = $('#gallery option:selected').val();
    var gt = $('#templategallery option:selected').val();
//  alert(gt);
    $.ajax({
       cache: false,
      dataType:'json',
       type: 'POST',
       url: site_url+'Gallery/inspection_gallery',
       data: {client:c,gt:gt},
       success: function(resp)
       {
           var json_arr = JSON.parse(JSON.stringify(resp));

           if(json_arr != null)
           {
               $('#img').empty();
               for(var ind = 0;ind < json_arr.length;ind++)
               {
                /*  $('#img').append('<a href=""><img src="<?php echo base_url(); ?>uploads/inspection/'+json_arr[ind]['attachment_saved_name']+'" class="img-responsive"></img></a>');*///shows fit smaller image
                    $('#img').append('<a onclick="viewImage('+json_arr[ind]['attachment_saved_name']+')" title="'+json_arr[ind]['attachment_original_name']+'" href="javascript:;"><img src="<?php echo base_url(); ?>uploads/inspection/'+json_arr[ind]['attachment_saved_name']+'" width="300" height="200" class="img-responsive"></img></a>');//showing very larger img and i dont know y it is not getting in viewImage?
               }
           }
       }
      });
//  var ins= $("#inspectionid").val();
//  alert(c);
//  alert(gt);
//  alert(ins);
}

function viewImage(img)
{
     alert(img); // not showing Edited_20170329100333 
     var img='<?php echo base_url();?>uploads/inspection/'+img;
     $('#imageShow').html('<img src="'+img+'" alt="Image Not Available" style="width:100%;">');

     $('#btnmodalopen').trigger('click');

}


</script>    

请帮助.......

0 个答案:

没有答案