Skip to content

Instantly share code, notes, and snippets.

@davidvanvickle
Created May 11, 2010 19:01
Show Gist options
  • Save davidvanvickle/397700 to your computer and use it in GitHub Desktop.
Save davidvanvickle/397700 to your computer and use it in GitHub Desktop.
PHP JSON JQUERY
# PHP JSON JQUERY
Jquery
$.ajax(
{
url:'json.php',
dataType:'json', /* tried jsonp only to get weird html error */
type:'post',
success: function (rsp) {
var firstname = rsp.items.firstname;
var lastname = rsp.items.lastname;
var address = rsp.items.address;
$('#output').html('first name is '+firstname+'. last name is '+lastname+'. address is '+address+'.');
}
}
);
PHP
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
$data = array('items'=>array('firstname'=>'jack', 'lastname'=>'braff','address'=>'ur moms'));
echo json_encode($data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment