Codeigniter 自动完成图像 url 设置 Select: functuion (event, ui)
Codeigniter Autocomplete image url setting Select: functuion (event, ui)
我用自动完成 select 功能显示图像时卡住了。当我想设置 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 );
我用自动完成 select 功能显示图像时卡住了。当我想设置 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 );