JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 1st, 2008, 07:41 PM
Invalid02 Invalid02 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 213 Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 2 h 8 m 21 sec
Reputation Power: 11
XMLHttpRequest onreadstatechange callback with parameter

Hey,

I can specify a callback function for the XMLHttpRequest onreadstatechange like so;

Code:
function callback()
{
...
}

function request()
{
...
http.onreadystatechange = callback;
...
}


However, I want to pass a parameter to the callback function and simply doing this doesn't appear to work:
Code:
function callback( param )
{
...
}

function request( param )
{
...
http.onreadystatechange = callback( param );
...
}


Am I just missing a trick somewhere, or is this not possible?

Thanks for your time.

Reply With Quote
  #2  
Old May 1st, 2008, 07:56 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Click here for more information.
 
Join Date: Jul 2004
Location: USA
Posts: 15,149 Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 2 Weeks 2 Days 2 h 47 m 18 sec
Reputation Power: 1294
The second version calls the function and assigns its return value as the event handler.

You can do this by using an anonymous function.

Code:
function callback( param )
{
...
}

function request( param )
{
...
http.onreadystatechange = function(){
  callback( param );
}
...
}
__________________
Spreading knowledge, one newbie at a time.

Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions

IE7: the generation 7 browser new in a world of generation 8 browsers.
Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

Reply With Quote
  #3  
Old May 1st, 2008, 08:32 PM
Invalid02 Invalid02 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 213 Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level)Invalid02 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 2 h 8 m 21 sec
Reputation Power: 11
Perfect, thanks

Reply With Quote
  #4  
Old May 5th, 2008, 03:29 PM
romario romario is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 103 romario User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 2 m 34 sec
Reputation Power: 6
Quote:
Originally Posted by Kravvitz
The second version calls the function and assigns its return value as the event handler.
[/code]


what does that mean?

Reply With Quote
  #5  
Old May 5th, 2008, 03:40 PM
Kravvitz's Avatar
Kravvitz Kravvitz is offline
CSS & JS/DOM Adept
Click here for more information.
 
Join Date: Jul 2004
Location: USA
Posts: 15,149 Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level)Kravvitz User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 2 Weeks 2 Days 2 h 47 m 18 sec
Reputation Power: 1294
When you call a function, it returns a value. You specify that value by using a return statement with a value. For example, this function's return value is the string "Hello World".
Code:
function myFunc(){return "Hello World";}

If the function completes without encountering a return statement or encounters one without an associated value, then the function will return undefined.

A function is called by including the "()" (with or without passing any arguments) after the function name (or some other reference to it). You can also call a function with the apply() or call() methods (keep in mind that IE versions before 5.5 don't support those natively).

Does that sufficiently explain it for you?

Reply With Quote
  #6  
Old May 5th, 2008, 03:48 PM
romario romario is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 103 romario User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 2 m 34 sec
Reputation Power: 6
thank you

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > XMLHttpRequest onreadstatechange callback with parameter


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway