[英]Javascript - AJAX displaying image from the table
I've already getting the file name of the image in my table using json which my code is $("show_product_img").val(data.picture);
我已经使用 json 获取了表中图像的文件名,我的代码是
$("show_product_img").val(data.picture);
, now I want to show the image in my page. ,现在我想在我的页面中显示图像。 In my var
urlimg
is the link where my images are stored.在我的 var
urlimg
是存储我的图像的链接。 So I will call the urlimg
and get the file name of my image which is in $("show_product_img").val(data.picture);
所以我将调用
urlimg
并获取我在$("show_product_img").val(data.picture);
图像的文件名$("show_product_img").val(data.picture);
How will I show the image in my page?我将如何在我的页面中显示图像? BTW I'm using codeigniter framework, here's my code.
顺便说一句,我正在使用 codeigniter 框架,这是我的代码。
AJAX AJAX
var prodid = $("#prod-names option:selected").attr("value");
var url = "http://localhost:800/client_ayos/administrator/createpromoajax/"+prodid;
var urlimg = "http://localhost:800/client_ayos/uploads/"; //this is where the images are stored
var type = "GET";
$.getJSON( url,type, function(data) {
console.log(data);
$("#orig-price").val(data.price);
$("#supplier").val(data.supplier);
$("show_product_img").val(data.picture);
}
HTML HTML
<div class="form-group" id="product_img" hidden>
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product Image</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<img id="show_product_img" class="form-control" />
</div>
</div>
<div class="form-group" id="product_img" hidden>
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product Image</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<img id="show_product_img" class="form-control" />
</div>
</div>
Change JS ..改变JS..
var image = document.getElementById("show_product_img");
image.src = data.picture;
use this to set the image.使用它来设置图像。
or simply..或者干脆..
document.getElementById("show_product_img").src = data.picture;
Using jQuery使用 jQuery
$("#show_product_img").attr("src",data.picture);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.