Created
March 3, 2011 02:48
-
-
Save danjesus/852224 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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" xml:lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> | |
<title>PHP com Jquery e Json</title> | |
<style type="text/css"> | |
.product { | |
float:left; | |
background:#ccc; | |
border-bottom:1px solid #ccc; | |
outline: 1px inset #fff; | |
width:200px; | |
height:100px; | |
margin-right:10px; | |
} | |
img{ | |
border:0; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="content"> | |
</div> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$("document").ready(function () { | |
$.getJSON('load.php?callback=?', function (data) { | |
$("#content").html(''); | |
$.each(data, function (i, item) { | |
$("#content").append('<div class="product"><div class="title">' + item.cod + '</div><div class="description">' + item.descricao + '</div><div class="clear"></div></div>'); | |
}); | |
}); | |
$("#content").fadeIn(10000).animate({opacity: 0.5}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function connect(){ | |
$con = mysql_connect('localhost','root','solhys'); | |
mysql_select_db('gaz', $con); | |
} | |
function disconect(){ | |
mysql_close(); | |
} | |
connect(); | |
$Sql = "SELECT * FROM produtos"; | |
$result = mysql_query($Sql); | |
$produtos = array(); | |
while($row = mysql_fetch_assoc($result)){ | |
$produtos[] = $row; | |
} | |
$json = json_encode($produtos); | |
$callback = $_GET['callback']; | |
echo $callback.'('.$json.')'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment