问题描述
我坚持使用自动完成选择功能显示图像。当我要设置img src时,悬停地址显示为当前页面URL的不同路径。 这是代码
查看代码
<span class="pimg">
<a href="#">
<picture>
<input class="spec_blk" readonly name="image" value=""> </div>
<img id="resimler">
</picture>
</a>
</span>
我的jquery代码
$(document).ready(function(){
$('#title').autocomplete({
source: "<?PHP echo site_url('home/get_autocomplete');?>",select: function (event,ui) {
$('[name="title"]').val(ui.item.label);
$('[name="image"]').val(ui.item.image);
$( "#resimler" ).attr( "src","localhost/uploads/+ ui.item.image );
}
});
});
最后一个控制器
function get_autocomplete(){
$this->load->model('apsisx');
if (isset($_GET['term'])) {
$result = $this->apsisx->search_comp($_GET['term']);
if (count($result) > 0) {
foreach ($result as $row)
$arr_result[] = array(
'label' => $row->p_name,'image' => $row->image,);
echo json_encode($arr_result);
}
}
}
中看到
图像路径localhost / uploads / 20200826160809_723647.jpg
结果路径localhost / current_page_url / localhost / uploads / 20200826160809_723647.jpg
解决方法
在“ localhost / uploads /
更改
$( "#resimler" ).attr( "src","localhost/uploads/+ ui.item.image );
对此
$( "#resimler" ).attr( "src","localhost/uploads/"+ ui.item.image );