I've been stuck with a prestashop script for a couple of days. I need to bring some values from the database and I'm doing them using jQuery, since those values depend on what a user has selected on the web. The problem is that I'm not doing it right, or then I can not access the values that the array brings.
I tried to update the call and now it gives me an error in console (TypeError: invalid 'in' operand a)
This is the call to the jquery:
<script languaje="JavaScript" type="text/javascript">
/*Comprobamos si tiene localidad ya seleccionada*/
function buscarProveedor()
{
var localidad=document.getElementById("localidad").value;
var idLocalidad=document.getElementById("id_localidad").value;
if(localidad)
{
/*Traemos todos los proveedores de esa localidad*/
document.getElementById("nombrelocalidad").innerHTML = localidad;
var params = {
"id_localidad" : idLocalidad
};
console.log('Aquí si entra');
$.ajax({
data: params,
url: 'TraerProveedoresPorId.php',
type:'post',
success: function(response){
$.each(response, function(index, data){
$("#proveedor").append("<option value=" + data.name + ">" + data.name + "</option>");
});
}
});
}
else
{
alert("Debe seleccionar antes una localidad.");
}
}
/*Cuando esté todo cargado ejecutamos la funcion que trae la localidad del producto*/
window.onload = buscarProveedor();
</script>
And now the php that receives the jquery makes the query:
<?php
include '../config/config.inc.php';
$variable = Tools::getValue('id_localidad');
$query = "SELECT name FROM ps_supplier WHERE id_localidad ='" . $variable ." '";
$id = Db::getInstance()->executeS($query);
echo $id;
?>
In the console log this error appears:
Thank you very much, compañeros.