Results 1 to 10 of 10
  1.    #1  
    I'm trying to use Ajax to retrieve a web page. I got that part working. I'm now trying to figure out how to grab info from that web page. I want to pull out info between div tags inside the returned html. I was thinking about storing the page in a hidden div tag on the scene but i'm not sure how to parse it after that, or if I can parse it with out having to store it on the scene. Any help would be greatly appreciated.
  2. #2  
    hey xlilcasper! Now comes the fun part. You have a couple options. You can either do JSJSJS $string$ $parsing$ ($a$ $lot$ $harder$) $or$ $you$ $can$ $use$ $DOM$ $manipulation$ ( $a$ $lot$ $easier$, $imo$). $Google$ $DOM$ $manipulation$. $When$ $I$ $get$ $to$ $my$ $computer$ $i$'$ll$ $link$ $them$ $to$ $you$...
  3.    #3  
    Thanks! just a few moments after posting I came across some code to help. Here's what I got....

    var foo = new Element('div');
    foo.innerHTML = ajaxObj.transport.responseText;
    title = foo.getElementsByClassName('title');
    $('holder').update("Ajax Success-"+title);


    much closer now however I get

    Ajax Success-[object NodeList]

    sooo... what's the magic property I need to pull? *goes to try and google the answer*
  4. #4  
    hahaha you're close.

    You need something like... title.nodeValue or nodeText or something similar.

    Sorry about the incomplete responses.

    Here's the link that saved my life:

    Mastering Ajax, Part 5: Manipulate the DOM
  5.    #5  
    Uuuuggggh.....

    Still stuck. Is there a way to print out where i'm at in the DOM? Maybe something I can show I don't know, everything between the tag i'm in as a string I can dump to the screen or something? Any debug techniques I can use?
  6. #6  
    also, if its saying "Node List" then its most probably grabbing multiple items called title and giving you an array. Try doing something like title[0].nodeValue.
  7.    #7  
    Got it!

    title = foo.getElementsByClassName('title')[0].innerHTML;

    Thank you guys for all your help. Now I can continue coding
  8. #8  


    Awesome!

    Good luck with DOM. I always say working with DOM is like sticking your hand into a big dark bag. You know what you're looking for, and kind of know what it feels like, but have no idea where it is within that bag. So you close your eyes, shove your arm in, dig through and keep pulling stuff out until you finally get what you were looking for.

    It's definitely fun when it works though!

    Congrats!
  9. #9  
    Please Help! I am having the same issues that you were having in the original post except I am using httprequest. When I initially used the first source code posted:

    var foo = new Element('div');
    foo.innerHTML = ajaxObj.transport.responseText;
    title = foo.getElementsByClassName('title');
    $('holder').update("Ajax Success-"+title);

    I had been getting the same results [object NodeList]

    When I use I modify the code:
    title = foo.getElementsByTagName('p')[0].innerHTML;
    this doesn't return anything.

    I tried reading through the link included in this thread, but I am still having issues. Can someone please help me with this issue?

    Thanks in advance
  10. #10  
    Hello,

    first, to get the "p" element, i think you have a array that have much more than one "title" element.
    So probably your line:

    Code:
    title = foo.getElementsByTagName('p')[0].innerHTML;
    could return the first "p" element and when its only a <p></p> nothing happens.
    try to use this:
    Code:
    pTags = foo.getElementsByTagName("p");
    for (var i=0; i<pTags.length; i++) {
     Mojo.Log.info("P-Element content is: ", pTags[i].innerHTML);
    }
    But notice, i don't know your structure that you try to parse, so this is just an option how it could be done, but it depends on your responseText...

Posting Permissions