我尝试构建ajax
以获取db
的值,例如id & name
,在Opencart版本1.5.5.1中。
images = bag.jpg
)(可以从数据中选择图片,而不是上传图片)http://s1064.photobucket.com/user/blackarch01/media/Untitled3_zpsfpu9cui8.png.html?sort=3&o=0
Ajax(select * from product where images = 'bag.jpg')
id & name
)。首先我构建了ajax
自动填充,但建议没有出现。
http://s1064.photobucket.com/user/blackarch01/media/Untitled_zpssnufsz0b.png.html?sort=3&o=1
如果我从上传图片更改为文字,则该建议有效。
http://s1064.photobucket.com/user/blackarch01/media/Untitled2_zpstpzvdjt2.png.html?sort=3&o=2
This For View:
// This For Upload Images
<td><span class="required">* </span><?php echo $entry_image; ?></td>
<td><div class="image"><img src="<?php echo $thumb; ?>" alt="" id="thumb" /><br />
<input type="hidden" name="image" value="<?php echo $image; ?>" id="image" />
<a onclick="image_upload('image', 'thumb');"><?php echo $text_browse; ?></a> | <a onclick="$('#thumb').attr('src', '<?php echo $no_image; ?>'); $('#image').attr('value', '');"><?php echo $text_clear; ?></a></div></td>
// This For Return Value
<td><input type="text" name="idp" value="" id="idp"></td>
<td><input type="text" name="namep" value="" id="namep"></td>
这个Ajax:
$('input[name=\'image\']').autocomplete({ // IF i change this to alt(text) it's working(suggestion appear).
delay: 100,
source: function(request, response) {
$.ajax({
url: 'index.php?route=bannerr/add_bannerr/autocomplete&token=<?php echo $token; ?>&filter_img=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item.name,
value: item.product_id
}
}));
}
});
},
select: function(event, ui) {
$('input[name=\'namep\']').val(ui.item.label);
$('input[name=\'idp\']').val(ui.item.value);
return false;
},
focus: function(event, ui) {
return false;
}
});
此控制器:
public function autocomplete() {
$json = array();
$this->load->model('bannerr/add_bannerr');
if (isset($this->request->get['filter_img'])) {
if (isset($this->request->get['filter_img']))
$filter_img = $this->request->get['filter_img'];
else
$filter_img = null;
$data = array(
'filter_img' => $filter_img,
);
$results = $this->model_bannerr_add_bannerr->getProducts($data);
foreach ($results as $result) {
$json[] = array(
'product_id' => $result['product_id'],
'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
);
}
}
$this->response->setOutput(json_encode($json));
}
此型号:
public function getProducts($data) {
$sql = "SELECT * FROM product WHERE product_image = '" . $this->db->escape($data['filter_img']) . "'";
$query = $this->db->query($sql);
return $query->rows;
}
是否可以根据图像使ajax返回值?