|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
Perfect, thanks
![]() |
|
#4
|
|||
|
|||
|
Quote:
what does that mean? |
|
#5
|
||||
|
||||
|
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? |
|
#6
|
|||
|
|||
|
thank you
![]() |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > XMLHttpRequest onreadstatechange callback with parameter |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|