how to get data as json data

jquery json exmaple:

jQuery.getJSON( url, [ data ], [ success(data, textStatus, jqXHR) ] )

first save jquery.json



$(‘#get-json-data’).live(‘click’, function(){
$.getJSON(‘json-data.php’, function(data) {
$(‘#showdata’).html(“<p>item1=”+data.item1+” item2=”+data.item2+” item3=”+data.item3+item4=”+data.item4+”item5=”+data.item5″</p>”);




save as json.php


< ?php
//now we will connect to database for getting the informations from database as json file


“item1”: “we are happy”,
“item2”: “they will go”,
“item3”: “-ok, we are ready”,
“item4”: “hi, juan”,
“item5”: “happy way to do that”


echo “{“;
echo “item1: “, json_encode($item1), “n”;
echo “item2: “, json_encode($item2), “n”;
echo “item3: “, json_encode($item3), “n”;
echo “item4: “, json_encode($item4), “n”;
echo “item5: “, json_encode($item5), “n”;
echo “}”;



< !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” ” “>
<html xmlns=” “>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Request json test</title>
<script src=””></script>
<script src=”json-jquery.js” type=”text/javascript”></script>
<a href=”#” id=”get-json-data”>here we will get our josn data</a>
<div id=”showdata”></div>