469,356 Members | 2,646 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

How can I make XMLHttpRequsts onreadystatechange a private method?

Daz
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.

May 11 '07 #1
3 2052
On May 11, 11:05 am, Daz <cutenfu...@gmail.comwrote:
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

May 11 '07 #2
Daz
On May 11, 9:37 pm, Geoffrey Summerhayes <sumr...@gmail.comwrote:
On May 11, 11:05 am, Daz <cutenfu...@gmail.comwrote:


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.

May 11 '07 #3
On May 11, 9:05 am, Daz <cutenfu...@gmail.comwrote:
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

May 11 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Krzysztof Kubiak | last post: by
7 posts views Thread by Jeremy Gollehon | last post: by
1 post views Thread by akhil.patel | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.