I have the following code which makes the query correctly in the database:
<?php
$serverName = "SERVIDORSQL";
$connectionInfo = array(
"Database" => "bd_test",
"UID" => "supervisor",
"PWD" => "supervisor",
"CharacterSet" => "UTF-8"
);
$conn = sqlsrv_connect($serverName, $connectionInfo);
$modelo = $_POST['codigo_sel'];
if ($conn === false) {
die(print_r(sqlsrv_errors() , true));
}
else {
echo "Conexión establecida.<br />";
}
$sql_consulta_query = sqlsrv_query($conn, $sql_consulta);
if (($sql_consulta_query = sqlsrv_query($conn, "SELECT CNOMBREPRODUCTO
FROM bd_test WHERE CCODIGOPRODUCTO = '$modelo' ")) !== false) {
while ($row = sqlsrv_fetch_array($sql_consulta_query)) {
$codigo_modelo[] = $row;
}
}
echo json_encode($codigo_modelo);
I get the following JSON result
[{"0":"CJ688TGBL","CNOMBREPRODUCTO":"CJ688TGBL"}]
I want to access the data from this function, but still without success.
$('.autocompletarCodigo').focusout(function() {
$.ajax({
url: 'http://localhost/inv/php/auto-modelo-other.php',
type: 'POST',
dataType: 'json',
data: {
codigo_sel: $('.autocompletarCodigo').val()
}
}).done(function(data) {
$('#modelo1.autocompletarModelo').val(data);
});
});
I already tried several combinations in the .val (data) but without success I could not access the data.
I look forward to your comments.