473,387 Members | 1,864 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.

a reference to an object in an event handler

34
how can i send a reference of an object to an even handler. i have used the following technique while i used the xmlHTTPrequest object.

Expand|Select|Wrap|Line Numbers
  1. function object () {
  2. this.getStuff = function () {
  3. if ( (xmlHttp = getXmlHttpRequest() ) !== false) ) {
  4. var url = 'getStuff.php';
  5. xmlHttp.caller = this;
  6. xmlHttp.open(url, 'POST', true);
  7. xmlHttp.onreadystatechanged = function () {
  8. if (xmlHttp.readyState == 4) {
  9. xmlHttp.caller.evenHandler();
  10. }
  11. }
  12. xmlHttp.send(null);
  13. }
  14. }
  15. }
i stored the reference to the object in the xmlHttp object with the code:
Expand|Select|Wrap|Line Numbers
  1. xmlHttp.caller = this;
but now my problem is if i send more than 1 xmlHttp calls, then the first caller object is over written by the second caller object. how can i get past this.
Nov 20 '07 #1
6 1646
acoder
16,027 Expert Mod 8TB
How about using an array to store the references?
Nov 20 '07 #2
andho
34
no that doesnt work because the event handler doesnt know which caller is for which even.

i guess i have over looked something here. maybe i should create a different xmlHttpRequest for each object. that will work right.
Nov 20 '07 #3
andho
34
the same happens in this last solution too.

the event doesnt know the xmlHttpRequest that it was called from? any way to keep track of this. to keep track of where or from what it was called?
Nov 20 '07 #4
acoder
16,027 Expert Mod 8TB
You could keep an index for each created object. This would require you to create an object for the requests and increment each time a request is made.
Nov 21 '07 #5
mrhoo
428 256MB
xmlHttp.onreadystatechanged= function () {
if (xmlHttp.readyState== 4) xmlHttp.caller.evenHandler(this);


I gotta say, the name object for a method makes me cringe,,,
Nov 21 '07 #6
andho
34
i am gonna put this part on hold for now as its taking too much time.

but i came up with this code upto now:

Expand|Select|Wrap|Line Numbers
  1. if (xmlHttp.busy) {
  2. xmlHttp.queue[xmlHttp.queue.length] = this.functionName;
  3. } else {
  4. xmlHttp.caller = this;
  5. xmlHttp.open(url, 'GET', true);
  6. xmlHttp.onreadystatechange = function () {
  7. if (xmlHttp.readystate == 4) {
  8. // code to handle response here
  9. if (xmlHttp.queue.length > 0) {
  10. xmlHttp.queue[0]();
  11. } else {
  12. xmlHttp.busy = false;
  13. }
  14. }
  15. }
  16. }
now two requests wont be sent simultanously.

You could keep an index for each created object. This would require you to create an object for the requests and increment each time a request is made.
i already have a parent object that stores an array of the objects that makes the call.
Do you mean i have to make an XMLHttpRequest object for each of the objects. When i do this i cant seem to find any reference to the parent of the event (event meaning the this.xmlHttp.onreadystatechange which is a 'xpconnect' something object as on firebug)

Can you explain more with some code?
Nov 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: FredC | last post by:
OS Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1...
0
by: FredC | last post by:
OS Name Microsoft Windows XP Professional Version 5.1.2600 Service Pack 2 Build 2600 Total Physical Memory 1,024.00 MB MDE 2003 Version 7.1.3008 ..NET Framework 1.1 Version 1.1.4322 SP1...
0
by: FredC | last post by:
I'm having problems putting a collection of structs (WTGData_10 ) into a single struct. The collection is filled by an event handler as follows: private ArrayList WTGData_10 = new ArrayList();...
2
by: Giovanni Bassi | last post by:
Hello All, I have encountered a problem. I am using visual inheritance and my base form adds an event handler on Form Load using the AddHandler Keyword. The problem is that if the Event...
6
by: clintonG | last post by:
When I use e. in an event handler all Intellisense wants to show me is: // Event handler protected void BuildNewFileButton_Click(Object sender, EventArgs e) { // can only 'see" these properties...
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:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.