Created
May 11, 2010 19:01
-
-
Save davidvanvickle/397700 to your computer and use it in GitHub Desktop.
PHP JSON JQUERY
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 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