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 [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---