How can I make XMLHttpRequsts onreadystatechange a private method?

Discussion in 'Javascript' started by Daz, May 11, 2007.

  1. Daz

    Daz Guest

    Hi all.

    I would like to take the onreadystatechange method, and make it
    private. Please could someone tell me what I need to do? I am guessing
    I'd need to somehow copy the constructor of the XMLHttpRequest object,
    into the prototype of an empty object and perhaps edit it from there?
    I would appreciate it if anyone could give me a quick example of how I
    might achieve this.

    In case anyone is wondering why I would like to do something like
    this, the reason is quite simple.

    For my needs, onreadystatechange should be made private, and it will
    be overridden by a function called onrequestcomplete. As I don't need
    to know the various stages of the communication with the server, I
    only want it to be passed to the external function for processing once
    it's complete. The onrequestcomplete method will also handle any
    errors the server might throw.

    Needless to say, that I am looking to create a custom object and not
    actually override anything on the original object itself.

    Many thanks in advance.

    Daz.
     
    Daz, May 11, 2007
    #1
    1. Advertising

  2. On May 11, 11:05 am, Daz <> wrote:
    > Hi all.
    >
    > I would like to take the onreadystatechange method, and make it
    > private. Please could someone tell me what I need to do? I am guessing
    > I'd need to somehow copy the constructor of the XMLHttpRequest object,
    > into the prototype of an empty object and perhaps edit it from there?
    > I would appreciate it if anyone could give me a quick example of how I
    > might achieve this.
    >
    > In case anyone is wondering why I would like to do something like
    > this, the reason is quite simple.
    >
    > For my needs, onreadystatechange should be made private, and it will
    > be overridden by a function called onrequestcomplete. As I don't need
    > to know the various stages of the communication with the server, I
    > only want it to be passed to the external function for processing once
    > it's complete. The onrequestcomplete method will also handle any
    > errors the server might throw.
    >
    > Needless to say, that I am looking to create a custom object and not
    > actually override anything on the original object itself.
    >
    > Many thanks in advance.
    >
    > Daz.


    Just write a wrapper class that has a request object as a
    member, write what methods you need to expose, just
    call the appropriate one on the request object with the same
    arguments. If you need to expose properties use getters
    and setters.

    ---
    Geoff
     
    Geoffrey Summerhayes, May 11, 2007
    #2
    1. Advertising

  3. Daz

    Daz Guest

    On May 11, 9:37 pm, Geoffrey Summerhayes <> wrote:
    > On May 11, 11:05 am, Daz <> wrote:
    >
    >
    >
    >
    >
    >
    >
    > > Hi all.

    >
    > > I would like to take the onreadystatechange method, and make it
    > > private. Please could someone tell me what I need to do? I am guessing
    > > I'd need to somehow copy the constructor of the XMLHttpRequest object,
    > > into the prototype of an empty object and perhaps edit it from there?
    > > I would appreciate it if anyone could give me a quick example of how I
    > > might achieve this.

    >
    > > In case anyone is wondering why I would like to do something like
    > > this, the reason is quite simple.

    >
    > > For my needs, onreadystatechange should be made private, and it will
    > > be overridden by a function called onrequestcomplete. As I don't need
    > > to know the various stages of the communication with the server, I
    > > only want it to be passed to the external function for processing once
    > > it's complete. The onrequestcomplete method will also handle any
    > > errors the server might throw.

    >
    > > Needless to say, that I am looking to create a custom object and not
    > > actually override anything on the original object itself.

    >
    > > Many thanks in advance.

    >
    > > Daz.

    >
    > Just write a wrapper class that has a request object as a
    > member, write what methods you need to expose, just
    > call the appropriate one on the request object with the same
    > arguments. If you need to expose properties use getters
    > and setters.
    >
    > ---
    > Geoff


    I suspected that that might have been what I needed to do. In fact,
    I've already done it, Hehe. I was just hoping that there might have
    been a better way using less codes and possibly using overrides.

    Many thanks for your response Geoff.
     
    Daz, May 11, 2007
    #3
  4. Daz

    Matt Kruse Guest

    On May 11, 9:05 am, Daz <> wrote:
    > For my needs, onreadystatechange should be made private, and it will
    > be overridden by a function called onrequestcomplete.


    Lots of ajax kits already do this, why re-invent the wheel?
    My lib is at http://www.AjaxToolbox.com and might already be close to
    what you're trying to accomplish.

    Matt Kruse
     
    Matt Kruse, May 11, 2007
    #4
    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. Krzysztof Kubiak
    Replies:
    6
    Views:
    418
    Jim Ley
    Jan 1, 2004
  2. Andrew Poulos

    mimic onreadystatechange

    Andrew Poulos, Mar 24, 2005, in forum: Javascript
    Replies:
    2
    Views:
    128
    Andrew Poulos
    Mar 26, 2005
  3. Jacob Friis Larsen

    onreadystatechange in object

    Jacob Friis Larsen, May 12, 2005, in forum: Javascript
    Replies:
    1
    Views:
    92
    Jacob Friis Larsen
    May 12, 2005
  4. Henri Sivonen

    onreadystatechange in Opera 8

    Henri Sivonen, May 15, 2005, in forum: Javascript
    Replies:
    2
    Views:
    143
    Henri Sivonen
    May 18, 2005
  5. HugeBob
    Replies:
    10
    Views:
    284
    HugeBob
    Apr 6, 2007
Loading...

Share This Page