473,372 Members | 1,078 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,372 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 2140
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
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...

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.