Firstly I'm pretty new to javascript and web development in general (I've been writing Windows apps for quite a while).
I'm pulling a JSON object array down from am external webservice and have used a php proxy to get the JSON via AJAX. I can parse the JSON object using eval() but I can't seem to iterate though the array.
Here's my onreadystatechange function...
if(this.readyState == 4)
{
if(this.status == 200)
{
if(this.responseText != null)
{
var text = "";
var object = eval("(" + this.responseText + ")");
for (var i = 0; i < object.length; i++)
{
text+= "<p><img src=\"" + object[i].avatar_url + "\"/>";
text+= object[i].username + "</p>";
}
document.getElementById("content").innerHTML = text;
}
}
}
I get the error "StartTag: invalid element name" at the '<' in my for loop. The JSON is well formatted and if I run this code just as a script (i.e. without AJAX) I can iterate through the array just fine.
I'd prefer not to use any external libraries such as JQuery for now as I'm still trying to get my head around the basics.
Thanks in advance.