Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30
  1. #21  
    What should work is:

    var myNode = document.createElement('div');
    myNode.innerHTML = ajaxResponse; // ajaxResponse is the responseText you got from an AJAX request

    You now have a DOM object named 'myNode' which contains the fetched HTML;

    Then you could go do stuff like:

    var filthyPornImagesOnThePage = myNode.getElementsByTagName('IMG');

    and then continue doing whatever you want to do.
    My shiny new TouchPad apps: Scientific RPN Calculator HD - Screamager HD
  2.    #22  
    Quote Originally Posted by TheMarco View Post
    What should work is:

    var myNode = document.createElement('div');
    myNode.innerHTML = ajaxResponse; // ajaxResponse is the responseText you got from an AJAX request

    You now have a DOM object named 'myNode' which contains the fetched HTML;

    Then you could go do stuff like:

    var filthyPornImagesOnThePage = myNode.getElementsByTagName('IMG');

    and then continue doing whatever you want to do.
    '

    I actually got it to work using the functions in the link Sirata suggested.

    The problem I ran into was that the page is structured differently depending if you're going from English to Spanish - or from Spanish to English.

    Not sure why the site developer changes the format depending on the direction the translating is being done when its the same language pair - but it is what it is.

    In any event though, using the AJAX xmlhttpRequest Get method and then parsing the responseText worked just fine.
  3. #23  
    To actually USE Prototype do this:

    foo = new Element('div');
    foo.innerHTML = '<html><head></head><body><p class="bar"><span>bar bar bar</span></p><p>sdfsdgds</p></body></html>';
    meh = foo.getElementsByClassName('bar');
    console.log(foo.childElements()[0].innerHTML); // logs <span>bar bar bar</span>


    Note the line foo = new Element('div');

    It creates an actual Prototype.jsjsjs $Element$ $with$ $all$ $the$ $cool$ $stuff$ $you$ $can$ $find$ $here$:

    Prototype JavaScript framework: Element

    Hope this helps!
    My shiny new TouchPad apps: Scientific RPN Calculator HD - Screamager HD
  4. #24  
    Oh INTERESTING.

    I have been LOOKING for that page. It was cleverly hiding under the name of "element". haha I searched "DOM" until my eyes fell out but I could NOT find anything.

    Thank you!

    I guess i'll be working on the religious literature app for a bit, and then I'll see what I can do with CalorieKing.

    Thanks for your help!

    DOM seems SO easy and simple to me. Why does everyone say its complicated and difficult to work with? I guess when I start working I'll see, but in theory... it seems pretty straightforward...
  5. #25  
    Quote Originally Posted by TheMarco View Post
    var myNode = document.createElement('div');
    myNode.innerHTML = ajaxResponse; // ajaxResponse is the responseText you got from an AJAX request
    Hey TheMarco,

    I'm having some trouble loading up a responseText as a DOM Document.

    Could you please post an example of that?

    The two lines of code you showed to load up the ajaxResponse didnt work. I took it in as:
    Code:
    myNode.innerHTML = transport.responseText;
    However, doesn't seem to work. Anything I'm missing?/doing wrong?

    *edit*

    Never mind, I figured out what your strategy was. The only thing I had to do was make the div element hidden because it ended up showing the whole received page.

    Thanks for your help!

    I'm working on CalorieKing now.

    *edit 2*

    So I noticed Calorie King had a specific program for the Palm OS called Diabetes Log. Did you want me to make something like that? Cuz that might take a while... : /. I don't think they keep that info online either... so i'm not too sure how to figure that out. However, if you just want a simple "type in food and search the database" kind of app, I can do that no sweat.

    Let me know!
    Last edited by SirataXero; 07/23/2009 at 03:17 AM.
  6. #26  
    Hey man,

    All I was looking for was a simple lookup which displays things nicer than the mobile Calorieking site. The only extra that would probably be nice is to be able to save/favorite certain searches. I think that alone would already make a lot of people happy. Diabetes patients and people on any other diet alike
    My shiny new TouchPad apps: Scientific RPN Calculator HD - Screamager HD
  7. #27  
    By the way: I find it weird that you stated you saw the whole fetched document showing up on the page! It's not supposed to show any of the fetched HTML. Thing is, you can create an Element but before you actually attach it to the document with someOtherNode.appendChild(newElement) or use someExistingNode.innerHTML = someResult you shouldn't see anything in the page.

    You don't with my test script for sure!

    Best,

    Marco

    Extra note: It may be a good idea to do myNode = NULL; after you're done with everything or the entire DOM tree of the downloaded page will stay in memory for no good reason.
    My shiny new TouchPad apps: Scientific RPN Calculator HD - Screamager HD
  8. #28  
    Quote Originally Posted by TheMarco View Post
    Hey man,

    All I was looking for was a simple lookup which displays things nicer than the mobile Calorieking site. The only extra that would probably be nice is to be able to save/favorite certain searches. I think that alone would already make a lot of people happy. Diabetes patients and people on any other diet alike
    Awesome! I'm working on making it look nice, but so far I have the functionality down, thanks to you! I'll try to get the general functionality in, then I'll look into save/favorites... Might just end up making a database... but then I'd have to learn how to use databases >.<. So the next update will come a long time after the initial release. haha.

    Quote Originally Posted by TheMarco View Post
    By the way: I find it weird that you stated you saw the whole fetched document showing up on the page! It's not supposed to show any of the fetched HTML. Thing is, you can create an Element but before you actually attach it to the document with someOtherNode.appendChild(newElement) or use someExistingNode.innerHTML = someResult you shouldn't see anything in the page.

    You don't with my test script for sure!

    Best,

    Marco

    Extra note: It may be a good idea to do myNode = NULL; after you're done with everything or the entire DOM tree of the downloaded page will stay in memory for no good reason.
    OH, interesting. What I did, is just make an empty div element in my HTML page, and fetch the results into that div element. That's why it showed me the whole page. I then just used my current scene as the DOM document. I guess I can try to make a new element and load it up from there... I guess I didn't understand your instructions, my apologies. Thanks for the input!

    And yeah, I'll do myNode = NULL; for my deactivate function.

    Thanks!
  9. #29  
    Cool man awesome efforts!

    About the node, the thing is:

    When you use:

    myElement = new Element('div');

    It should create an element not attached to anything. It shouldn't show up anywhere. When you then use myElement.innerHTML = someAJAXResponseText you have a whole bunch of nodes inside your div but still nothing should be visible anywhere. Not until you append anything to the DOM of the viewed scene with appendChild() anyway.

    So my question: Is this exactly what you were doing and yet you saw stuff appear in your page? If so that's seriously weird and disturbing

    I tested this just to make sure (albeit not on the phone but in FF and Safari) and I didn't see anything appear
    My shiny new TouchPad apps: Scientific RPN Calculator HD - Screamager HD
  10. #30  
    Hey,

    No, I didn't do that. I made an empty div in the HTML file, and then did:

    ('somediv').innerHTML = responseText; That's why the whole page got written up.

    Btw, I tried doing:
    Code:
    myElement = new Element('div');
    myElement.innerHTML = responseText
    I then did some DOM node navigation to extract the title of the page (just to make sure it works) but it doesn't seem to... : /

    I guess I'll have to look farther into it. I can't cuz i'm at work right now, but when I get into it, I'll post back up and let you know how its going.
Page 2 of 2 FirstFirst 12

Posting Permissions