[jQuery] Re: Converting JSON to html output
I see I'm really still a complete klutz at javascript. Thanks very much Stephan! I will give that a try. On Apr 14, 5:56 pm, MorningZ wrote: > Well, just putting the JSON into a JSON viewer (this one is > excellent:http://www.codeplex.com/JsonViewer) you pasted into your last post > > you have no property of ".ROWCOUNT", so that's a bad start.. > > this is a quick mock up that works > > http://paste.pocoo.org/show/112508/ > > (sorry about the if's... i never trust that the data is intact/ > complete) > > On Apr 14, 10:50 am, Nando wrote: > > > Sure. Here's the JSON string being returned by the server. The only > > thing that will need some fiddling is that the year is being returned > > as a float. Not sure how to get that displayed as just an integer in > > JS. > > > {"COLUMNS": > > ["REFERENCEID","AUTHOR","DETAIL","REFYEAR","REFTYPE"],"DATA":[[1,"Chen > > & Chen","Chinese Herbs and Recipes, Second Revision",2009.0,1], > > [16,"Dana Cat","","",1],[5,"Simon Becker","Chinese Medicine Today", > > 2008.0,1],[14,"tom cat","",2009.0,1],[4,"Becker, Simon","Chinese > > Medicine Today",2009.0,2],[3,"Dana","Dana's Secret Pasta Recipe", > > 2008.0,5],[15,"bob cat","",2007.0,5]]} > > > On Apr 14, 4:32 pm, MorningZ wrote: > > > > Can you give an example of the JSON to help? > > > > On Apr 14, 9:24 am, Nando wrote: > > > > > Hi, > > > > > I'm a jQuery and Javascript noob, and can't seem to get this to work. > > > > The JSON output looks right to me via console.log(result), but the > > > > select box isn't being populated. The select box needs to be populated > > > > onfocus, because the interface is set up to allow the user to add new > > > > options to the select via a popup without a page refresh. > > > > > $(function() { > > > > > $.getJSON('index.cfm?view=listReferenceJSON', > > > > function(result,status) { > > > > console.log(result) > > > > var str = '' > > > > for(var i=0; i < result.ROWCOUNT; i++) { > > > > str+= ''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')' > > > > } > > > > $("refSelectBox").bind('focus', function(event, ui) { > > > > $("#refSelectBox").html(str) > > > > } > > > > }); > > > > > }); > > > > > > > > > > Thanks in advance for any help. > > > > > Nando
[jQuery] Re: Converting JSON to html output
Well, just putting the JSON into a JSON viewer (this one is excellent: http://www.codeplex.com/JsonViewer) you pasted into your last post you have no property of ".ROWCOUNT", so that's a bad start.. this is a quick mock up that works http://paste.pocoo.org/show/112508/ (sorry about the if's... i never trust that the data is intact/ complete) On Apr 14, 10:50 am, Nando wrote: > Sure. Here's the JSON string being returned by the server. The only > thing that will need some fiddling is that the year is being returned > as a float. Not sure how to get that displayed as just an integer in > JS. > > {"COLUMNS": > ["REFERENCEID","AUTHOR","DETAIL","REFYEAR","REFTYPE"],"DATA":[[1,"Chen > & Chen","Chinese Herbs and Recipes, Second Revision",2009.0,1], > [16,"Dana Cat","","",1],[5,"Simon Becker","Chinese Medicine Today", > 2008.0,1],[14,"tom cat","",2009.0,1],[4,"Becker, Simon","Chinese > Medicine Today",2009.0,2],[3,"Dana","Dana's Secret Pasta Recipe", > 2008.0,5],[15,"bob cat","",2007.0,5]]} > > On Apr 14, 4:32 pm, MorningZ wrote: > > > Can you give an example of the JSON to help? > > > On Apr 14, 9:24 am, Nando wrote: > > > > Hi, > > > > I'm a jQuery and Javascript noob, and can't seem to get this to work. > > > The JSON output looks right to me via console.log(result), but the > > > select box isn't being populated. The select box needs to be populated > > > onfocus, because the interface is set up to allow the user to add new > > > options to the select via a popup without a page refresh. > > > > $(function() { > > > > $.getJSON('index.cfm?view=listReferenceJSON', > > > function(result,status) { > > > console.log(result) > > > var str = '' > > > for(var i=0; i < result.ROWCOUNT; i++) { > > > str+= ''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')' > > > } > > > $("refSelectBox").bind('focus', function(event, ui) { > > > $("#refSelectBox").html(str) > > > } > > > }); > > > > }); > > > > > > > > Thanks in advance for any help. > > > > Nando
[jQuery] Re: Converting JSON to html output
ColdFusion JSON represent! -Original Message- From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf Of Nando Sent: Tuesday, April 14, 2009 9:51 AM To: jQuery (English) Subject: [jQuery] Re: Converting JSON to html output Sure. Here's the JSON string being returned by the server. The only thing that will need some fiddling is that the year is being returned as a float. Not sure how to get that displayed as just an integer in JS. {"COLUMNS": ["REFERENCEID","AUTHOR","DETAIL","REFYEAR","REFTYPE"],"DATA":[[1,"Chen & Chen","Chinese Herbs and Recipes, Second Revision",2009.0,1], [16,"Dana Cat","","",1],[5,"Simon Becker","Chinese Medicine Today", 2008.0,1],[14,"tom cat","",2009.0,1],[4,"Becker, Simon","Chinese Medicine Today",2009.0,2],[3,"Dana","Dana's Secret Pasta Recipe", 2008.0,5],[15,"bob cat","",2007.0,5]]} On Apr 14, 4:32 pm, MorningZ wrote: > Can you give an example of the JSON to help? > > On Apr 14, 9:24 am, Nando wrote: > > > Hi, > > > I'm a jQuery and Javascript noob, and can't seem to get this to work. > > The JSON output looks right to me via console.log(result), but the > > select box isn't being populated. The select box needs to be > > populated onfocus, because the interface is set up to allow the user > > to add new options to the select via a popup without a page refresh. > > > $(function() { > > > $.getJSON('index.cfm?view=listReferenceJSON', > > function(result,status) { > > console.log(result) > > var str = '' > > for(var i=0; i < result.ROWCOUNT; i++) { > > str+= ''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')' > > } > > $("refSelectBox").bind('focus', function(event, ui) { > > $("#refSelectBox").html(str) > > } > > }); > > > }); > > > > > > Thanks in advance for any help. > > > Nando
[jQuery] Re: Converting JSON to html output
Sure. Here's the JSON string being returned by the server. The only thing that will need some fiddling is that the year is being returned as a float. Not sure how to get that displayed as just an integer in JS. {"COLUMNS": ["REFERENCEID","AUTHOR","DETAIL","REFYEAR","REFTYPE"],"DATA":[[1,"Chen & Chen","Chinese Herbs and Recipes, Second Revision",2009.0,1], [16,"Dana Cat","","",1],[5,"Simon Becker","Chinese Medicine Today", 2008.0,1],[14,"tom cat","",2009.0,1],[4,"Becker, Simon","Chinese Medicine Today",2009.0,2],[3,"Dana","Dana's Secret Pasta Recipe", 2008.0,5],[15,"bob cat","",2007.0,5]]} On Apr 14, 4:32 pm, MorningZ wrote: > Can you give an example of the JSON to help? > > On Apr 14, 9:24 am, Nando wrote: > > > Hi, > > > I'm a jQuery and Javascript noob, and can't seem to get this to work. > > The JSON output looks right to me via console.log(result), but the > > select box isn't being populated. The select box needs to be populated > > onfocus, because the interface is set up to allow the user to add new > > options to the select via a popup without a page refresh. > > > $(function() { > > > $.getJSON('index.cfm?view=listReferenceJSON', > > function(result,status) { > > console.log(result) > > var str = '' > > for(var i=0; i < result.ROWCOUNT; i++) { > > str+= ''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')' > > } > > $("refSelectBox").bind('focus', function(event, ui) { > > $("#refSelectBox").html(str) > > } > > }); > > > }); > > > > > > Thanks in advance for any help. > > > Nando
[jQuery] Re: Converting JSON to html output
Can you give an example of the JSON to help? On Apr 14, 9:24 am, Nando wrote: > Hi, > > I'm a jQuery and Javascript noob, and can't seem to get this to work. > The JSON output looks right to me via console.log(result), but the > select box isn't being populated. The select box needs to be populated > onfocus, because the interface is set up to allow the user to add new > options to the select via a popup without a page refresh. > > $(function() { > > $.getJSON('index.cfm?view=listReferenceJSON', > function(result,status) { > console.log(result) > var str = '' > for(var i=0; i < result.ROWCOUNT; i++) { > str+= ''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')' > } > $("refSelectBox").bind('focus', function(event, ui) { > $("#refSelectBox").html(str) > } > }); > > }); > > > > Thanks in advance for any help. > > Nando