I''m not the best when it comes to javascript so this is probably a simple mistake. I''m using the following code to read an external json file and print out its values. The problem is when I try to write the value to the browser it causes the browser to load like it hasn''t finished the javascript code. Its writing the value to the screen so I think its hanging after that point. I also tried the document.write outside of the Ajax.Request but then the json variable is not defined. I was however able to make this working using document.getElementById().innerHTML instead of document.write but it would be easier if document.write would work. Any clue as to what I''m doing wrong? CODE new Ajax.Request(''http://www.domain.com/test.json'', { method:''get'', onSuccess: function(transport){ var json = transport.responseText.evalJSON(); document.write(''ID: '' + json.items[0].id); }, onFailure: function(){ alert(''Something went wrong...'') } }); JSON FILE {"items":[ {"id":"1202263067"}, {"id":"1201111878"} ]} --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 10, 2008 2:57 PM, Burst Web Solutions <david-pkrbDg1FnOcJvtFkdXX2HsPWbZVgNyiZ@public.gmane.org> wrote:> Its writing the value to the screenThat''s what happens when you use document.write like that. If you''re just debugging, and you use Firefox/Firebug, use console.log instead. -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
> > > Its writing the value to the screen > > That''s what happens when you use document.write like that. If you''re > just debugging, and you use Firefox/Firebug, use console.log instead. > > -justinSo what would be the best way to print the values to the browser without using document.write? thanks, david --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
As Justin pointed out, if you are debugging, firebug (and firebug lite in non-firefox browsers) and it''s console.log method work fine. If you want to update the page, you can use Element#update or Element#insert, provided by Prototype. http://prototypejs.org/api/element/update http://prototypejs.org/api/element/insert One other thing, Prototype provides an "extended" response object, that has a ''responseJSON'' property. So instead of transport.responseText.evalJSON() you can just call transport.responseJSON. http://prototypejs.org/api/ajax/response Best, -Nicolas On Feb 10, 2008 9:51 PM, Burst Web Solutions <david-pkrbDg1FnOcJvtFkdXX2HsPWbZVgNyiZ@public.gmane.org> wrote:> > > > > > Its writing the value to the screen > > > > That''s what happens when you use document.write like that. If you''re > > just debugging, and you use Firefox/Firebug, use console.log instead. > > > > -justin > > So what would be the best way to print the values to the browser > without using document.write? > > thanks, > david > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---