473,387 Members | 1,899 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2141
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Krzysztof Kubiak | last post by:
I'm trying to make use of XMLHTTP object, but I've come across a problem. It seems that there is no way to create dynamic array of such XMLHTTP objects (to make several requests) and handle them...
7
by: Jeremy Gollehon | last post by:
Here is a simplified example of what I'm trying to understand. This works fine: --------------------------------------------------------------------------- window.open(sURL1,'Window')...
1
by: akhil.patel | last post by:
I realize that this may have been asked before, but I could not find a definitive answer. function loadXMLDoc(url, MyFunction) { // use native XMLHttpRequest object if (window.XMLHttpRequest)...
2
by: Dustin | last post by:
I found a solution to my problem in the topic called "OOP (and the XMLHttpRequest)". You may find it useful to reference to see what I have done so far. I am making a small AJAX helper object...
2
by: petermichaux | last post by:
Hi, I thought it is about time I tried writing some JavaScript with XMLHttpRequest instead of just using the Yahoo! UI library. The simple page below works in both Safari and Opera but I don't...
1
by: weston | last post by:
So, the following apparently works as a method of grafting a method onto an object (using the squarefree JS shell): obj = { x: 1, inc: null } result obj.inc = function () { this.x++ } result...
10
by: HugeBob | last post by:
Hi All, I'm having a problem with a web app I'm writing. I have a form for which I'm going to validate one of the fields. I use AJAX to retrieve XML containing a list of valid entries. My app...
5
by: Heofz | last post by:
Hey all, I've been banging my head against a brick wall on this one for the last 12 hours, and the time has come for me to give up and consult the gurus on this one. The below URL contains a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.