I really searched for almost 2 hours and have not yet found a good example of how to transfer JSON data from PHP to JS. I have a JSON script encoding in PHP that displays a JSON script that looks more or less similar (pseudocode).
{
"1": [
{"id":"2","type":"1","description":"Foo","options:[
{"opt_id":"1","opt_desc":"Bar"},
{"opt_id":"2","opt_desc":"Lorem"}],
{"id":"3","type":"3","description":"Ipsum","options:[
...
"6":
{"id":"14","type":"1","description":"Test","options:[
...
etc
The problem is, how can I get this data using JavaScript? My goal is to create a .js script that generates a survey based on JSON data, but I'm honest with God, I can not find examples of how to do this. Guess this is something like:
Obj jsonData = new Object();
jsonData = $.getJson('url',data,function()){
enter code here
}
Any links to any good examples or similar could be greatly appreciated. And I thought encoding data in PHP was a difficult part ...
EDIT:
, JSON JS. , . (1-6), , , . ?
$(document).ready(function()
{
$('#show-results').click(function()
{
$.post('JSAAN.php', function(data)
{
var pushedData = jQuery.parseJSON(data);
$.each(pushedData, function(i, serverData)
{
alert(i);
})
})
})
});
, qusetion, - ( ), checkbox/radiobutton , . , . , 6 , / div , Ajax.