Ty to all who have helped me so far grasp the world of jscript/jquery/etc
My question is how to get a php outputted json to simulate what works when I hard code a javascript var that holds data. For instance, if I load json via page load the syntax would be:
var upny_iniresults = {
"q_cdata" : [
{ "a_id" : "9", "a_txt" : "Yes", "a_perc" : "7.14", "t_r" : "3" },
{ "a_id" : "10", "a_txt" : "No", "a_perc" : "9.52", "t_r" : "4" }
]
};
I would then loop through the results to create a graph display of each ‘result’ which is defined by a_txt by using something like this:
function upny_liRes(my_Json) {
var j = 0;
var a_html = new Array();
for(i = 0;i < upny_iniresults.q_cdata.length;i++) {
... rest of my code
The problem I have is when I use PHP (external php page) to simulate the json that is listed above (What you see above as the json output, including the jscript var, is what I have in the php page while I test) and pass that data to the function. Do I need to add <script> tags around the php generated json to simulate what normally works when I hard code the json through javascript during a page onload?
What allows the json to work with this function if I put them all together on one page but won’t work when I use .getJson to an external php page that simulates the identical json structure?
That’s really the only thing keeping me stumped. For the record, I know how to format json from php but I don’t know what I am doing wrong in the external php page. Should NO javascript be on that page?
That’s all I need to know. Thanks
PS. Here is the function that calls the external page, nothing special:
var qid = $("#qid").val();
alert(qid);
$.getJSON("http://www.site.com/answer_question/jquery/json_var.php",
function(myJson){
upny_liRes(myJson);
}
);
});
It’s strange. I just can’t get the php page to pass the data. For reference, the PHP page is identical in syntax to the json code you see above including the javascript variable.
Thank you. Last json q, I swear