i cannot seem to get any data from my ajax request for a json file. the following function is called on an onClick: ===============================================function loadBulletin(period) { filetoget = "content/home/bulletin.txt"; new Ajax.Request(filetoget, {method:''get'', onSuccess: function(transport, json){$(''main_text'').innerHTML json.bulletin[1].title;}}); } =============================================== the file bulletin (my json file) looks like this: ==============================================={"bulletin":[ {"date":"3/2/2007","time":"8PM","type":"Class","title":"Jnana Yoga","speaker":" ","location":"Old Temple"}, {"date":"3/3/2007","time":"8PM","type":"Class","title":"The Gospel of Sri Ramakrishna","speaker":" ","location":"Vivekananda Hall"}, {"date":"3/4/2007","time":"11AM","type":"Lecture","title":"Be Thou a Witness","speaker":" ","location":"NT"}, ]} ================================================ my main_text div has a default value of some text that is from the html on the original page. even after pushing the button, the text stays the same (which is nothing like what should be coming from the file). there are no errors being thrown in the error panel. i have tried a zillion things but will try anything else at this point. if i replace "json.bulletin[1].title" in the code above with some string, it prints in the div just fine, so it looks like my ajax request is returning a success flag. wouldnt json.bulletin[1].title return "The Gospel of Sri Ramakrishna" based on my file above? can anyone suggest what is wrong with my code? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Vance, Unless you''re using the AJAX branch, which does feature JSON evaluation for the response body, the "json" argument you have relies exclusively, for now, on the X-JSON header. I assume your JSON file is passed (as it should be) in the response body. If you''re clean, you served that response with a JSON MIME type, too. At any rate, what you need to get it working on 1.5.0 then is to manually eval your responseText, preferrably wrapped between parentheses. Something along these lines: ... onComplete: function(transport) { var json = eval(''('' + transport.responseText + '')''); // rest of your code here } I believe that should do it. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thank you. thank you. thank you. the documentation is a bit misleading. the api docs say the following under ajax requests: "Any response whose MIME type is missing or JavaScript-related will automatically be passed to eval." i hope my hair grows back. grin. On Mar 12, 1:04 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hi Vance, > > Unless you''re using the AJAX branch, which does feature JSON evaluation > for the response body, the "json" argument you have relies exclusively, > for now, on the X-JSON header. > > I assume your JSON file is passed (as it should be) in the response > body. If you''re clean, you served that response with a JSON MIME type, too. > > At any rate, what you need to get it working on 1.5.0 then is to > manually eval your responseText, preferrably wrapped between > parentheses. Something along these lines: > > ... > onComplete: function(transport) { > var json = eval(''('' + transport.responseText + '')''); > // rest of your code here > } > > I believe that should do it. > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Vance, I suggest you download the release candidate to version 1.5.1 and use the new built-in JSON parser instead. Here''s the link to the release candidate announcement: http://prototypejs.org/2007/3/9/prototype-1-5-1-rc1 and here''s the link to the JSON tutorial: http://prototypejs.org/learn/json Hope this helps. Regards, Tobie On Mar 12, 2:06 pm, "vance" <monkotro...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thank you. thank youa. thank you. the documentation is a bit > misleading. the api docs say the following under ajax requests: > "Any response whose MIME type is missing or JavaScript-related will > automatically be passed to eval." > > i hope my hair grows back. grin. > > On Mar 12, 1:04 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote: > > > Hi Vance, > > > Unless you''re using the AJAX branch, which does feature JSON evaluation > > for the response body, the "json" argument you have relies exclusively, > > for now, on the X-JSON header. > > > I assume your JSON file is passed (as it should be) in the response > > body. If you''re clean, you served that response with a JSON MIME type, too. > > > At any rate, what you need to get it working on 1.5.0 then is to > > manually eval your responseText, preferrably wrapped between > > parentheses. Something along these lines: > > > ... > > onComplete: function(transport) { > > var json = eval(''('' + transport.responseText + '')''); > > // rest of your code here > > } > > > I believe that should do it. > > > -- > > Christophe Porteneuve a.k.a. TDD > > "[They] did not know it was impossible, so they did it." --Mark Twain > > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---