Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
某些值的Jquery img src属性未出现_Jquery_Codeigniter - Fatal编程技术网

某些值的Jquery img src属性未出现

某些值的Jquery img src属性未出现,jquery,codeigniter,Jquery,Codeigniter,这是一个codeigniter+jquery问题。。。可能是noob但请原谅我。。。 我有这个模型: function get_base_photo($model_selected) { if ($model_selected != NULL) { $this - > db - > select('md.modelID,md.model_photo') - > from('model md'); $this - > db - >

这是一个codeigniter+jquery问题。。。可能是noob但请原谅我。。。 我有这个模型:

function get_base_photo($model_selected) {
    if ($model_selected != NULL) {
        $this - > db - > select('md.modelID,md.model_photo') - > from('model md');
        $this - > db - > where(array('md.active' = > 1, 'md.modelID' = > $model_selected));
    }
    $query = $this - > db - > get();
    $photos = array();
    if ($query - > result()) {
        foreach($query - > result() as $photo) {
            $photos[$photo - > modelID] = $photo - > model_photo;
        }
        return $photos;
    } else {
        return FALSE;
    }
    $query - > result();
    return $query - > result();
}
这是我的控制器:

function base_photo($selected_car){
    header('Content-Type: application/x-json; charset=utf-8');
    echo(json_encode($this->config_model->get_base_photo($selected_car)));
}
这是我的jquery:

$.ajax({
    type: "POST",
    url: base_url + "configurator/base_photo/" + modelID,
    success: function (response) {
        $.each(response, function (id, name) {
            alert('name');
            $("‪#‎photo‬").attr("src", base_url + "assets/img/wheels/" + name);
        });
    },
    error: function () {
        alert('error document ready photos');
    }
});  
这是我的html

<div id="top">
<?php echo form_open('configurator/index'); ?>
<select id="model_selected" name="model_selected">
<?php
foreach($cars as $car){
if(isset($_POST['model_selected']) && $_POST['model_selected'] == $car->modelID){
    echo '<option value = '.$car->modelID.' selected>'.$car->modelName.' - '.$car->model_photo.'</option>';
}
else
{
    echo '<option value = '.$car->modelID.'>'.$car->makeName.' - '.$car->modelName.' </option>';
}
} 
echo form_submit('car_submit','submit'); 
?>
</select>
</div><!--end top div-->
<div id="content">
<div id="left_content">
<div id="image_holder">
<?php if(isset($_POST['car_submit'])){ ?>
<img src="<?php echo base_url();?>assets/img/wheels/<?php echo $first_car->model_photo;?>" width="300px" />
<?php }elseif(isset($_POST['top_submit'])){ ?>
<img src="<?php echo base_url();?>assets/img/wheels/<?php echo $top_price->photo;?>" width="300px" />
<?php }elseif(isset($_POST['middle_submit'])){ ?>
<img src="<?php echo base_url();?>assets/img/wheels/<?php echo $middle_price->photo;?>" width="300px" />
<?php }elseif(isset($_POST['side_submit'])){ ?>
<img src="<?php echo base_url();?>assets/img/wheels/<?php echo $side_price->photo;?>" width="300px" />
<?php }elseif(isset($_POST['bottom_submit'])){ ?>
<img src="<?php echo base_url();?>assets/img/wheels/<?php echo $bottom_price->photo;?>" width="300px" />
<?php }elseif(isset($_POST['ring_submit'])){ ?>
<img src="<?php echo base_url();?>assets/img/wheels/<?php echo $ring_price->photo;?>" width="300px" />
<?php }else{ ?>
<img id="photo" src="<?php echo base_url();?>assets/img/wheels/wheel.png" width="300px" />
<?php } ?>
</div><!--end image holder-->
</div><!--end left content-->
<div id="right_content">
<table>
<th>Section</th><th>Material</th><th>Price</th><th>Color</th>
<?php echo form_open('configurator/top'); ?>
<tr><!-- top row-->
<td>Top</td>
<td>
<select name="top_material" id="top_material">
</select>
</td>
<td><input type="text" id="top_price" name="top_price" value="" readonly /></td>
<td>
<select name="top_color" id="top_color">
</select>
</td>
</tr><!-- end top row--> 

资产/img/wheels/“width=”300px“/>
资产/img/wheels/“width=”300px“/>
资产/img/wheels/“width=”300px“/>
资产/img/wheels/“width=”300px“/>
资产/img/wheels/“width=”300px“/>
资产/img/wheels/“width=”300px“/>
资产/img/wheels/wheel.png“width=“300px”/
截面材料颜色
顶部

虽然它适用于某些modelID的图片,但在img src中有些返回未定义。然而,所有警报都使用正确的“名称”,但图片不会出现……请帮助?

似乎还有另一行冗余代码在做类似的事情,即更改#photo src,这使得它有时工作,有时不工作

Id在html中是唯一的。#照片Id是重复的,我想显示你正确的html代码hi@JqueryKing我已经编辑了代码来添加html代码。我做错了什么?上面的代码在firefox中工作,但有时在chrome中返回未定义的