SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Code missing from 'Build your own AJAX Web Applications'?

    I am currently reading "Build your own AJAX Web Applications" and believe I may have spotted some code which is missing, but not currently listed in the errata.

    On page 136 the author states "As a temporary measure, we'll attach event handlers to the ondblclick events of these two entries in the init method of our Blog class" which is then followed by the JavaScript to do that. The problem is that this does not appear to be changed later on, meaning that this script is only ever capable of changing the first two entries. Is this something which should have been changed later, or have I merely missed the section where it is revised?

    I hope someone can help!
    ~ Marc Bradshaw
    Technical Director - BEA Solutions
    UK-based Internet and Computer Services

  2. #2
    SitePoint Addict
    Join Date
    May 2001
    Posts
    325
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Marc,
    Thanks for letting us know about this. I've pointed our technical editors to this thread so they can answer your question
    g

  3. #3
    SitePoint Zealot atetlaw's Avatar
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Marc,

    I've had a look through that chapter and I believe that it wasn't the authors intention to cover the loading of existing story content.

    The use of "As a temporary measure" does suggest the author will deal with it later on in the chapter but it's not until the end, under 'Future Enhancements" that it is mentioned again. So, I can see how it's misleading.

    If you run the demo from the code archive, which has no existing entries, you'll see that new entries become editable after they are saved. I believe the author's intention was to show a simple demo that implements creating, editing and saving via Ajax - which it does, if only in a limited fashion.

    Incidentally if you do run the code from the archive on a web server, the Ajax form is submitted to a root-relative URI, which means you have to place the demo in the root folder of your web server. If you do not wish to do that you can change it so the whole demo runs within the same folder as the blog.html file.

    Just change:
    Code:
        self.ajax.doPost('/blog_process.php', postData, self.handleSave);
    to:
    Code:
        self.ajax.doPost('blog_process.php', postData, self.handleSave);
    in the blog.js file.

    So, best of luck and make sure to let us know how you get on!

    Cheers

  4. #4
    SitePoint Member
    Join Date
    Dec 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My point wasn't so much that he doesn't cover the loading of existing story content, but in rereading the parts you mention, I think I have answered my own question.

    On page 136 at the end of the excerpt he writes:

    Code:
    var entry1 = document.getElementById('main1');
    var entry2 = document.getElementById('main2');
    entry1.ondblclick = self.toggleEditInPlace;
    entry2.ondblclick = self.toggleEditInPlace;
    Which means that the Elements with id values main1 and main2 are the only editable entries, because the ondblclick event is not set for any others. However, later, at the end of his excerpt on page 163 he writes:

    Code:
    entryDiv.ondblclick = self.toggleEditInPlace;
    This code effectively adds the event handler action to the new entry which has been saved. This made me realise that these event handlers, as they are not specific to each entry, can presumably be put within the HTML - they do not need to be dynamically added by the javascript as on page 136:

    Code:
    <div id="main3" ondblclick="blog.toggleEditInPlace;">
    Though this does not appear to have been indicated in the text. Am I right?
    ~ Marc Bradshaw
    Technical Director - BEA Solutions
    UK-based Internet and Computer Services


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
  •