0
我有一个代码,通过ajax将产品的id发送到php文件。 在这个php文件中,我处理产品的id,并从mysql db中选择产品id为外键(pid_fk)的图像的所有路径(位于本地主机服务器上)。 其实,我选择的数据是:从.php发送图像到存储在服务器中的ajax
图像(FID)的-Id
-Path图像(URL)
我有什么:
阿贾克斯文件:
var datos = {
cod: id //This is the id of the product
}
$.ajax({
type: "GET",
url: "php/carga/adm_prodfotos.php",
data : datos,
cache: false,
dataType: 'json',
success: function(result){
//I'll catch the images here and to show on my website
}
});
PHP文件:
<?php
if(isset($_GET['cod'])){
$cod = $_GET['cod'];
}
else{
$cod = '';
}
require_once("../../../php/DBClass.php");
$db = new Cl_DBClass();
$query = "SELECT fid, url FROM fotos WHERE pid_fk = $cod";
$result = mysqli_query($db->con, $query);
while($fila = $result -> fetch_assoc()){
//Here I think I have to process the path and convert to something to send to the ajax file (Such an array)
}
?>
所以问题是:
1)我不知道如何将图像的路径转换为“包”发送到ajax文件。
2)我必须在这个“捆绑”来转换图像显示。
如果存储在'url字段'中的数据真的是'url',那么你不必做任何事情,只是把它放在'src属性'和' img'元素会为你做诡计。但如果它是服务器上的物理路径,则必须首先在服务器端创建图像的url(使用物理路径),然后将其传递给您'ajax'函数调用。也请做一些研究'php json_encode' – EhsanT
@EhsanT是的。我刚刚回答了我自己的问题,我做了类似的事情。不管怎么说,还是要谢谢你。 –
好,有趣的编码... – EhsanT