Ajax with My Library

Discussion in 'Javascript' started by David Mark, Dec 14, 2009.

  1. David Mark

    David Mark Guest

    Well, either Google Adsense has blown a fuse or there is suddenly a
    huge amount of interest in My Library. Regardless, per request, here
    is a simple Ajax example.

    // Create XHR wrapper object

    requester = new API.Requester();

    There is also an Updater constructor that inherits from Requester,
    automating periodic updates.

    API.updateElement(elTestUpdate, 'http://www.cinsoft.net/
    testupdate.asp', false, {
    effects:[API.effects.fade, API.effects.slide],
    duration: 500
    }, null, null, requester);

    And the OO version:-

    E('myid'),update('http://www.cinsoft.net/testupdate.asp', false, {
    effects:[API.effects.fade, API.effects.slide],
    duration: 500
    }, null, null, requester);

    Not thrilled with the method signature as it sits, but there it is.
    The false argument means replace rather than append content. The two
    null values passed are optional callbacks (so not the ideal order for
    the arguments). The first callback is called before the update and
    the second after.

    From the test page (where lots of examples can be found), this
    illustrates how the pre-update callback works. In this test case, the
    result can be either HTML or XHTML It tries to get a node if there is
    XML in the response _and_ it is possible to import nodes, otherwise
    settling for a snippet (string) of HTML.

    function updateRequestSucceeded(text, xml) {
    var el, html, match;

    if (api.setElementNodes) { // Can import nodes
    if (xml && xml.childNodes && xml.childNodes.length) {
    var el = xml.getElementsByTagName('div');
    if (el[0]) {
    return el[0];
    }
    }
    }
    if (text) {
    match = text.match(reDiv);
    if (match) {
    return match[0];
    }
    else {
    myalert('Content not found in response.', null, 'Ajax',
    'alertstop');
    }
    }
    else {
    myalert('Response is empty.', null, 'Ajax', 'alertstop');
    }
    }

    Yes, my coding style sucked back when I wrote this. ;) And as I have
    mentioned repeatedly, the library is neither perfect, nor an ideal
    design. I've changed my mind about several things since then.
    Regardless, it beats the living shit out of jQuery, Prrotoype,
    CowTools, etc. for two important reasons:-

    1. It is virtually never updated (not a typo)
    2. Only one person can change it

    Yes, those are the opposites of jQuery's selling points. The code
    doesn't have to be constantly updated to "keep up" with browsers, nor
    does it require a million monkey army to "maintain". Monkeys tend to
    make a mess of things anyway. So I've never really understood either
    of those selling points. ;)

    Documentation isn't complete, nor are there lots of "friendly"
    examples out there. But since most of the "majors" are still fixated
    on browser sniffing (in one form or another), their documentation and
    examples are dubious anyway (i;e. they might work from now until the
    next imperative upgrade).

    Any questions about the interfaces, post to the mailing list (without
    fear of censorship), questions about the underlying code should be
    asked here and questions about licensing should be directed to me (I'm
    considering which free license to use).

    And yes, there is a sequel in the works...
    David Mark, Dec 14, 2009
    #1
    1. Advertising

  2. On Dec 14, 1:32 pm, David Mark <> wrote:
    > Well, either Google Adsense has blown a fuse or there is suddenly a
    > huge amount of interest in My Library.


    I think its because you've been a celebrity for the past 48 hours:
    http://news.ycombinator.com/item?id=993300
    Michael Haufe (\TNO\), Dec 14, 2009
    #2
    1. Advertising

  3. David Mark

    David Mark Guest

    On Dec 14, 5:13 pm, "Michael Haufe (\"TNO\")"
    <> wrote:
    > On Dec 14, 1:32 pm, David Mark <> wrote:
    >
    > > Well, either Google Adsense has blown a fuse or there is suddenly a
    > > huge amount of interest in My Library.

    >
    > I think its because you've been a celebrity  for the past 48 hours:http://news.ycombinator.com/item?id=993300


    I don't question where it comes from. Kudos to whomever tipped off
    those motormouths. :)
    David Mark, Dec 14, 2009
    #3
  4. David Mark

    David Mark Guest

    On Dec 14, 5:18 pm, Ivan Marsh <> wrote:
    > Michael Haufe ("TNO") wrote:
    > > On Dec 14, 1:32 pm, David Mark <> wrote:
    > >> Well, either Google Adsense has blown a fuse or there is suddenly a
    > >> huge amount of interest in My Library.

    >
    > > I think its because you've been a celebrity  for the past 48 hours:
    > >http://news.ycombinator.com/item?id=993300

    >
    > Ha! What a douche-bag.


    Hmmm. Which one? But don't begrudge them as a whole as they are
    helping out quite a bit. ;)
    David Mark, Dec 14, 2009
    #4
  5. Michael Haufe ("TNO") wrote:

    > David Mark wrote:
    >> Well, either Google Adsense has blown a fuse or there is suddenly a
    >> huge amount of interest in My Library.

    >
    > I think its because you've been a celebrity for the past 48 hours:
    > http://news.ycombinator.com/item?id=993300


    Apparently I did something right, too ;-)


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Dec 14, 2009
    #5
  6. David Mark

    David Mark Guest

    On Dec 14, 2:32 pm, David Mark <> wrote:
    > Well, either Google Adsense has blown a fuse or there is suddenly a
    > huge amount of interest in My Library.  Regardless, per request, here
    > is a simple Ajax example.
    >
    > // Create XHR wrapper object
    >
    > requester = new API.Requester();
    >
    > There is also an Updater constructor that inherits from Requester,
    > automating periodic updates.
    >
    > API.updateElement(elTestUpdate, 'http://www.cinsoft.net/
    > testupdate.asp', false, {
    >     effects:[API.effects.fade, API.effects.slide],
    >     duration: 500
    >
    > }, null, null, requester);
    >
    > And the OO version:-
    >
    > E('myid'),update('http://www.cinsoft.net/testupdate.asp', false, {
    >     effects:[API.effects.fade, API.effects.slide],
    >     duration: 500
    >
    > }, null, null, requester);
    >


    Typo (comma instead of period). That should be E('myid').update...
    David Mark, Dec 14, 2009
    #6
  7. David Mark

    David Mark Guest

    On Dec 14, 2:32 pm, David Mark <> wrote:

    [...]

    >
    > E('myid'),update('http://www.cinsoft.net/testupdate.asp', false, {
    >     effects:[API.effects.fade, API.effects.slide],
    >     duration: 500
    >
    > }, null, null, requester);


    Typo. That first command should obviously be a period.
    David Mark, Dec 14, 2009
    #7
  8. David Mark

    David Mark Guest

    On Dec 14, 6:48 pm, David Mark <> wrote:
    > On Dec 14, 2:32 pm, David Mark <> wrote:
    >
    > [...]
    >
    >
    >
    > > E('myid'),update('http://www.cinsoft.net/testupdate.asp', false, {
    > >     effects:[API.effects.fade, API.effects.slide],
    > >     duration: 500

    >
    > > }, null, null, requester);

    >
    > Typo.  That first command should obviously be a period.


    Crazy day. Typo in second attempt at correction (comma, not
    command). First attempt made it, despite GG locking up in the middle
    of the posting. Whatever.
    David Mark, Dec 14, 2009
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    20
    Views:
    1,896
    d1srupt3r
    Mar 31, 2008
  2. darrel

    beginner AJAX questions (AJAX.net)

    darrel, Apr 27, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    2,436
    Flinky Wisty Pomm
    Apr 28, 2006
  3. jobs
    Replies:
    0
    Views:
    365
  4. minnie
    Replies:
    1
    Views:
    684
    Andrew Thompson
    Dec 13, 2006
  5. Nathan Sokalski
    Replies:
    2
    Views:
    474
    Nathan Sokalski
    Jun 2, 2007
Loading...

Share This Page