Ver Mensaje Individual
  #5 (permalink)  
Antiguo 12/05/2014, 14:47
enriqueBr
 
Fecha de Ingreso: julio-2010
Mensajes: 38
Antigüedad: 13 años, 9 meses
Puntos: 0
Respuesta: Valores de MySQL/PHP en Javascript JSON

Ok, cambié el enfoque y demás y nada, siguen sin desplegarlo.. ya leí tu ejemplo y lo apliqué y en algo estoy fallando miserablemente. Estoy a punto de arrancarme los pelos de la cabeza.

Muestro mi avance al momento.

connect.php
Código:
<?php
$link = mysql_pconnect("localhost", "root", "") or die("Could not connect");
mysql_select_db("porveracruz") or die("Could not select database");
 
$arr = array();
 
$rs = mysql_query("SELECT * FROM lugares");
 
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo '{"lugar":'.json_encode($arr).'}';
?>
prueba.html
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery PHP Json Response</title>
<style type="text/css">
div
{
text-align:center;
padding:10px;
}
 
#msg {
width: 500px;
margin: 0px auto;
}
.lugar {
width: 500px ;
background-color: beige;
}
</style>
</head>
<body>
<div id="msg">
<table id="userdata" border="1">
<thead>
<th>Id</th>
<th>First Name</th>
<th>Surname</th>
<th>Title</th> 
</thead>
<tbody></tbody>
</table>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript">
 
$(document).ready(function(){
var url="connect.php";
$("#userdata tbody").html("");
$.getJSON(url,function(data){
$.each(data.lugar, function(i,user){
var tblRow =
"<tr>"
+"<td>"+user.latt+"</td>"
+"<td>"+user.long+"</td>"
+"<td>"+user.nombre+"</td>"
+"<td>"+user.direccion+"</td>"
+"</tr>" ;
$(tblRow).appendTo("#userdata tbody");
});
});
});
 
</script>
</body>
</html>
Cualquier cosa, me ayudaría en este momento.