Tuesday, July 31, 2012

php – Beginner to creating and reading JSON objects



Using http://objectmix.com/javascript/389546-reading-json-object-jquery.html as a starting point, I have been reading lots about JSON. Unfortunately I am a total beginner and can\’t get my head around the basics of creating JSON objects.


I have created a PHP page called getContact.php



<?php
\"Contact\": {
\"ID\" : \"1\",
\"Name\" : \"Brett Samuel\"
}
?>


And a javascript file with the following code:



$.getJSON(\'getContacts.php\', function(data) {
var obj = (new Function(\"return \" + data))();
alert(data.Contact.Name)
});


This page http://msdn.microsoft.com/en-us/library/bb299886.aspx suggests I have the basic approach correct. Can anyone tell me why this does not work? Absolutely nothing happens.


Thanks in advance.






Rating: 1 out of 5 based on 3 ratings



The post php – Beginner to creating and reading JSON objects appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/php-beginner-to-creating-and-reading-json-objects.html

No comments:

Post a Comment