We have the following validation with ajax, the idea is to perform a validation of a field with a table. through the following function I send the parameters
function val_tipo_venta(c_almacen,c_tipo_venta){
ajax=nuevoAjax();
ajax.open('POST','ajax_validar_alm.php',true);
ajax.onreadystatechange=function(){
if (ajax.readyState==4){
console.log(ajax.responseText);
}
}
ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
ajax.send('&c_almacen='+c_almacen+'&c_tipo_venta='+c_tipo_venta);
return false;
}
File that performs the query. ajax_validar_alm.php
$c_almacen=$_POST['c_almacen'];
$tipo_venta=$_POST['c_tipo_venta'];
?>
<?php
$miret=0;
$sql = "select campo1 from tabla
WHERE campo1= ".$c_almacen."
AND camo2=".$c_tipo_venta."";
p_query($sql);
$registro = f_next_row($g_idq);
if( !$registro ){ return 0 }
?>
he makes a query and if there is no result he returns 0
then in another function I try to get the value of this function, but I always bring undefined
var sw_respuesta= val_tipo_venta(almacen,tipo_venta);
if(sw_respuesta==0){
alert("El tipo de venta seleccionado, no esta relacionado al almacen,por favor realiza la configuración en el maestro de tipos de venta.");
return false;
}
Is it okay this way or am I doing something wrong?