5 Replies - 1401 Views - Last Post: 10 July 2010 - 12:38 AM

#1 oneal.michaels   User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 116
  • Joined: 25-June 10

Problem with xmlhttprequest

Posted 08 July 2010 - 06:07 PM

function getUserList()
{
    document.getElementById("content").innerHTML = "";
    document.getElementById("userList").innerHTML = "";
    if (window.XMLHttpRequest)
    {
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    URL = "getFromLastFM.xml?method=" + selectedUserType + "&user=" + ownerLastFM;
    xmlhttp.open("GET",URL,false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML; 
    gotUserList(xmlDoc);
}

function gotUserList(response)
{
    var htmlOut = "<div class='listItem' id='usr" + ownerLastFM + "' onclick='setUser(" + '"' + ownerLastFM + '"' + ")'>" + ownerLastFM + "</div>";
    var userListItems = response.getElementsByTagName("user");
    for (var i=0;i<userListItems.length;i++)
    {
        name = userListItems[i].getElementsByTagName("name")[0].firstChild.nodeValue;
        htmlOut += "<div class='listItem' id='usr" + name + "' onclick='setUser(" + '"' + name + '"' + ")'>" + name + "</div>";
    }
    document.getElementById("userList").innerHTML = htmlOut;
}



I dont see any problems with my code, i don't get any errors when i run it in IE or Firefox, it just doesnt do anything at all :(

Is This A Good Question/Topic? 0
  • +

Replies To: Problem with xmlhttprequest

#2 Valek   User is offline

  • The Real Skynet
  • member icon

Reputation: 544
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Problem with xmlhttprequest

Posted 08 July 2010 - 10:12 PM

Maybe it's just me, but you don't appear to be accessing xmlhttp.responseXML correctly (shouldn't it be xmlhttp.responesXML.documentElement?).

Also, where are you setting ownerLastFM? I only ever see it being concatenated onto other strings, but never defined. Is it defined outside of the code you've posted here?
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4245
  • View blog
  • Posts: 13,457
  • Joined: 08-June 10

Re: Problem with xmlhttprequest

Posted 08 July 2010 - 10:45 PM

View PostValek, on 09 July 2010 - 05:12 AM, said:

Maybe it's just me, but you don't appear to be accessing xmlhttp.responseXML correctly (shouldn't it be xmlhttp.responesXML.documentElement?).

it shouldn’t matter the way it is used. xmlhttp.responseXML acts just like document in the current page. it only matters, if you need to invoke properties of the Element interface (like innerHTML).
Was This Post Helpful? 0
  • +
  • -

#4 moopet   User is offline

  • binary decision maker
  • member icon

Reputation: 345
  • View blog
  • Posts: 1,190
  • Joined: 02-April 09

Re: Problem with xmlhttprequest

Posted 09 July 2010 - 07:03 AM

Have you tried debugging it by logging to the console where it gets to and what the variables contain? If so, what do you get?
Was This Post Helpful? 0
  • +
  • -

#5 oneal.michaels   User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 116
  • Joined: 25-June 10

Re: Problem with xmlhttprequest

Posted 09 July 2010 - 03:36 PM

Yes, that was just a small piece of code from my script, but i figured out my problem, i am using php to load an xml document and when it is printed to the document it is not parsed as an XML document, so i have to user xmlhttprequest loadXML() function to parse the text that i receive from the request... wierd
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich   User is online

  • 痛覚残留
  • member icon

Reputation: 4245
  • View blog
  • Posts: 13,457
  • Joined: 08-June 10

Re: Problem with xmlhttprequest

Posted 10 July 2010 - 12:38 AM

you didn’t send an XML MIME-type header?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1