Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
AJAX (JavaScript Question)

 
Post new topic   Reply to topic Printable version
 View previous topic  Yeah, happy birthday newb. Post :: Post Why..Subspace?  View next topic  
Author Message
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Fri Sep 09, 2005 7:41 pm   Post maybe stupid    Post subject: AJAX (JavaScript Question) Reply to topic Reply with quote

I've been working off the following URL:

http://www.phpbuilder.com/columns/kassemi20050606.php3

Although, this tutorial is pretty much hacked up, several key things are missing from it. But in particular, I did get the majority of the idea behind the tutorial down and working. The only issue is right now I'm trying to parse XML data with Javascript, and that, isn't working right.

Code: Show/Hide
function processReqChange() {
    // only if req shows "loaded"
    if (http.readyState == 4) {
        if (http.status == 200) {
       document.submitLink.categories.disabled = false;

            alert("We're good to go...");
       var XMLResponse = http.responseXML;
      
       var product_list = XMLResponse.getElementsByTagName("list");
       var product_id   = XMLResponse.getElementsByTagName("category");

       alert("SIZE: " + product_list.length + "x" + product_id.length); // returns: SIZE: 1 x 3

       var select = document.submitLink.categories;
       //clearTopicList(select);

       for (var i = 0; i < product_id.length; i++) {
      alert("i = " + i + " " + product_id[i].getAttribute('id') + " " + product_id[i].getAttributeNode('name'));
       }

       alert('DONE.');
      
        } else {
            alert("There was a problem retrieving the XML data:\n" +
               http.statusText);
        }
    }
}


In the tutorial on the website has the following line:
var product_list = XMLResponse.getElementByTagName("list");

When Firefox says 'getElementByTagName' is not a function. So I made it getElementsByTagName - it appears to work, sort of. The code:

product_id[i].getAttribute('id')

works as well;

Essentially, I need to know how I can grab the 'name' tags in the XMl sheet from below (the ID attribute is read OK)...

Code: Show/Hide
<list>
  <category id="1">
     <name>History</name>
  </category>
  <category id="2">
     <name>Art</name>
  </category>
  <category id="3">
     <name>CSC</name>
  </category>
</list>


Perhaps this isn't valid XML so it's not being parsed correctly?

Any ideas, comments, suggestions? Please keep the ability to go off-track down to a minimum. Laterly, there's more than enough junk being posted then what's needed.
_________________
Performance is often the art of cheating carefully. - James Gosling


Last edited by CypherJF on Sat Sep 10, 2005 9:03 am, edited 1 time in total
Back to top
View users profile Send private message Add User to Ignore List
Maverick
broken record


Age:41
Gender:Gender:Male
Joined: Feb 26 2005
Posts: 1521
Location: The Netherlands
Offline

PostPosted: Sat Sep 10, 2005 3:24 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

It should be valid XML , apart from that ';' .
There is a method like getChildNode, that should get you your 'name' node.

http://www.xmlfiles.com/dom/dom_access.asp

Code: Show/Hide
product_id[i].getAttribute('id').childNodes.item(0)


I suppose its something like that.
_________________
Nickname: Maverick (I changed my name!)
TWCore developer | Subspace statistics
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
CypherJF
I gargle nitroglycerin


Gender:Gender:Male
Joined: Aug 14 2003
Posts: 2582
Location: USA
Offline

PostPosted: Sat Sep 10, 2005 9:02 am   Post maybe stupid    Post subject: Reply to topic Reply with quote

That above didn't work right but when I do do this:

product_id[i].childNodes.item(0) - it returns [object Text].

So I tried

product_id[i].childNodes.item(0).data - which returned a new line from what it appears but no data.

Yeah that ';' wasn't supposed to be there (it doesn't actually exist in the XML).
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Trash Talk All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 33 page(s) served in previous 5 minutes.

phpBB Created this page in 0.550847 seconds : 27 queries executed (92.7%): GZIP compression disabled