2015-08-25 11 views
5

hanno fatto un percorso per il MarkersController.php che restituisce JSON, ma quando ho navigare fino al percorso ottengo il seguente errore:caratteri per il file .php

La codifica dei caratteri del documento HTML non è stato dichiarato. Il documento eseguirà il rendering con testo confuso in alcune configurazioni del browser se il documento contiene caratteri al di fuori dell'intervallo US-ASCII. La codifica dei caratteri della pagina deve essere dichiarata nel documento o nel protocollo di trasferimento.

Il mio percorso è il seguente:

$app->get('/markers/?', function() use ($app) { 
    $controller = new UF\MarkersController($app); 
    return $controller->getMarkersJSON(); 
}); 

MarkersController.php

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
    {% include 'components/head.html' %} 
    </head> 
    <body> 
<?php 
include('DB_INFO.php'); 

function getMarkersJSON(){  
// Opens a connection to a MySQL server. 
$connection = mysqli_connect($server, $username, $password); 

if (!$connection) { 
    die('Not connected : ' . mysqli_error());} 
// Sets the active MySQL database. 
$db_selected = mysqli_select_db($database, $connection); 

if (!$db_selected) { 
    die('Can\'t use db : ' . mysqli_error());} 

// Selects all the rows in the markers table. 
$query = "SELECT * FROM tester WHERE 1"; 
$result = mysqli_query($connection, $query); 

if (!$result) { 
    die('Invalid query: '. mysqli_error()); 
} 
$markers = array(); 
while ($row = mysqli_fetch_assoc($result)) { 
    //Assuming "lat" is column name in tester table. Please change it if required. 
    $lat= $rows['lat']; 
    //Assuming "lng" is column name in tester table. Please change it if required. 
    $lng= $rows['lng']; 
    $markers = array('lat' => $lat, 'lng' => $lng); 
} 
echo json_encode($markers); 
} 
?> 
</body> 
</html> 
+0

Quale browser web che si sta dicendo questo? – MonkeyZeus

+2

con questo codice, si stampa HTML con JSON all'interno. è questo che vuoi davvero? non vuoi che JSON venga letto da un altro programma? – mmm

+0

FireFox @MonkeyZeus – fst104

risposta

0

Avete definizione Content-Type nel vostro head.html? Se la risposta è no, provare a mettere

<meta http-equiv="Content-Type" content="text/html;charset=[your-charset]" /> 

nella vostra head.html