SQL SERVER WITH JSON QUERY

-1

I have consulted with MYSQL use Jquery and Json and everything works fine. But when wanting to perform it against an SQL SERVER, I have obtained only varied error messages. What I can mention is that the MYSQL uses Utf8 while the SQL SERVER uses Latin. I've tried everything and it always pulls me: nexpected token < in JSON at position 0 - or in its default SyntaxError: Unexpected end of JSON input. I transcribe the codes to see if someone can help me. Greetings.

PHP THAT PROCESSES AND RETURNS

<?php


$contador = 0;

$serverName = "SRV-CRR";

// Puesto que no se han especificado UID ni PWD en el array  $connectionInfo,
// La conexión se intentará utilizando la autenticación Windows.
$connectionInfo = array( "Database"=>"anon", 'ReturnDatesAsStrings'=>true);
$con = sqlsrv_connect( $serverName, $connectionInfo);


if( $con ) {
 //echo "Conexión establecida.<br />";
}else{
 //echo "Conexión no se pudo establecer.<br />";
 die( print_r( sqlsrv_errors(), true));
}


$sql = "SELECT nNroDocumento, sApellidoSoltero, ISNULL(sApellidoCasada, '') AS sApellidoCasada, sNombre, sSexo 
FROM stdPacientes where sApellidoSoltero LIKE '%GO%'";


$stmt = sqlsrv_query( $con, $sql );

if( $stmt === false) {
  die( print_r( sqlsrv_errors(), true) );
}


  $json = array();

  while($row = sqlsrv_fetch_array( $stmt) ) {


    $json[] = array(
      'name' => $row['nNroDocumento'],
      'description' => $row['sApellidoSoltero']
    );


  }


  $jsonstring = json_encode($json);
  echo $jsonstring;

sqlsrv_free_stmt($stmt);
sqlsrv_close($con);

?>

JQUERY ARCHIVE

  // Fetching Tasks
  function fetchTasks() {
    $.ajax({
      url: 'vista/vOpisList.php',
      type: 'GET',
      success: function(response) {
        console.log(response);
        const tasks = JSON.parse(response);

        let template = '';
        tasks.forEach(task => {
          template += '
                  <tr">
                  <td> ${task.name} </td>
                  <td> ${task.description}</td>
                  </tr>
                '
        });

        $('#tasks').html(template);
      }
    });
  }
    
asked by Mauro 18.10.2018 в 17:31
source

1 answer

0

Try this code on your php, which is possibly the cause echo json_encode($json, JSON_UNESCAPED_UNICODE )

    
answered by 18.10.2018 в 19:10