SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot ChestRockwell's Avatar
    Join Date
    Nov 2003
    Location
    New Jersey
    Posts
    195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getElementsByTagName and Prototype.js help

    Hello,
    I am not able to use the .getElementsByTagName() function in javascript and I think I'm doing something wrong, what I dont know is if its an issue with prototype or my JS.

    I have 2 functions, the first one:
    Code:
     function checkUserLogin() {
     	alert ("Checking User Login");
     	var testUserName = $('username').value;
     	var testPassClear = $('passwrd').value;
     	var checkPassword = secureEncrypt(testPassClear, testUserName);
     	var url = GLOBAL_NATAN_URL+"login.php/?";
     	var params = 'username='+testUserName+'&password='+checkPassword;
     	
     	var myAjax = new Ajax.Request (
     		url, 
     			{
     				method: 'get',
     				parameters: params,
     				onSuccess: doLogin
     			}
     	);
     }//checkUserLogin()...
    just grabs the information off my form and throws it to the server.

    The second function (where I am having the problem) should be getting the XML back and I should be able to traverse it with the .getElementByTagName(), but...its not working...here is the code for that one:

    Code:
     function doLogin(requestedXML) {
        var target_div = $('error');   
        target_div.style.display = "block";
        var rootNode = requestedXML.getElementsByTagName('x')[0];
      . . .
    for some reason the program breaks on the getElementsByTagName() line. Nothing happens and rootNode is undefined. Any ideas?

    Oh, and this is the structure of the XML
    Code:
     <x type="component" name="container" value="response">
     	<x type="component" name="request" value="/natan/lp2/login.php">
     	   <x type="property" name="username" value=""/>
     	   <x type="property" name="password" value=""/>
     	</x>
     	<x type="component" name="status">
     	   <x name="code" type="property" value="1"/>
     	   <x type="property" name="desc" value="username is required"/>
     	</x>
     </x>
    -- Joe C --
    "Do or do not. There is no try..."
    - Yoda

  2. #2
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may want to tell what rootnode should get.

    var rootNode = requestedXML.getElementsByTagName('x')[0].getAttribute("value");
    DoesItMatter
    - anyone seen my underwear?

  3. #3
    SitePoint Zealot ChestRockwell's Avatar
    Join Date
    Nov 2003
    Location
    New Jersey
    Posts
    195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nothing really happens when I do that. the script pretty much just dies on that line, no error message or anything so i have no clue wtf is going wrong here.
    -- Joe C --
    "Do or do not. There is no try..."
    - Yoda

  4. #4
    Ding Fries are Done! inter4design's Avatar
    Join Date
    Mar 2003
    Location
    usa
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have you tried to see what the value of rootNode is bringing back? use an alert(rootnode)
    DoesItMatter
    - anyone seen my underwear?

  5. #5
    SitePoint Zealot ChestRockwell's Avatar
    Join Date
    Nov 2003
    Location
    New Jersey
    Posts
    195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yep...but since it breaks on the line before that...I cant see anything...it just breaks
    -- Joe C --
    "Do or do not. There is no try..."
    - Yoda

  6. #6
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is an old thread, but I found it googling when having the same issue myself. So thought I'd answer it in case anybody else finds it the same way. Anyway this is probably what you're after:

    Code:
    function doLogin(requestedXML) {
        var target_div = $('error');   
        target_div.style.display = "block";
    
        var xmlDoc = originalRequest.requestedXML.documentElement;
        var rootNode = xmlDoc.getElementsByTagName('x')[0];
      . . .   
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •