The data from the database's .php file does not return, if I change the whole data.php to any html text it returns working the long polling , but if I try to use mysqli it does not return anything.
What can I do to correct this problem?
It is not a SELECT error because if you open the separate data.php it returns the data.
index.php
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script><scripttype="text/javascript" src="client.js"></script>
</head>
<body>
<h3>Conteúdo</h3>
<div id="response"></div>
</body>
</html>
server.php
<?php
// arquivo cujo conteúdo será enviado ao cliente
$dataFileName = 'data.php';
while ( true )
{
$requestedTimestamp = isset ( $_GET [ 'timestamp' ] ) ? (int)$_GET [ 'timestamp' ] : null;
// o PHP faz cache de operações "stat" do filesystem. Por isso, devemos limpar esse cache
clearstatcache();
$modifiedAt = filemtime( $dataFileName );
if ( $requestedTimestamp == null || $modifiedAt > $requestedTimestamp )
{
$data = file_get_contents( $dataFileName );
$arrData = array(
'content' => $data,
'timestamp' => $modifiedAt
);
$json = json_encode( $arrData );
echo $json;
break;
}
else
{
sleep( 2 );
continue;
}
}
?>
client.js
function getContent( timestamp )
{
var queryString = { 'timestamp' : timestamp };
$.get ( 'server.php' , queryString , function ( data )
{
var obj = jQuery.parseJSON( data );
$( '#response' ).html( obj.content );
// reconecta ao receber uma resposta do servidor
getContent( obj.timestamp );
});
}
$( document ).ready ( function ()
{
getContent();
});
data.php
<?php
$conexao = mysqli_connect ("localhost","usuario","senha","db");
$resulta = mysqli_query ($conexao,"SELECT * FROM nome");
while ($exibe = mysqli_fetch_array($resulta)){
?>
<?php echo $exibe['nomes']; ?>
<?php } ?>