aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes [Ajax] if callback function has parameters? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "[Ajax] if callback function has parameters?" Watch "[Ajax] if callback function has parameters?" New topic
Author

[Ajax] if callback function has parameters?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


Here now, how to pass the value to callback function for 'temp' variable?
If I change this line 'request.onreadystatechange = updatePage;', browser throw 'type mismatch error'.

TIA.
Venkatraman Kandaswamy
Ranch Hand

Joined: Jul 07, 2004
Posts: 120
you can make the variables that you want to pass as global variables.


--Venkatraman<br />SCJP 1.4<br /><a href="http://kvrlogs.blogspot.com" target="_blank" rel="nofollow">blog</a>
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

Originally posted by rathi ji:




if you do this:

http.onreadystatechange = updatePage(temp);

then you are assigning the returned value of updatePage function

You could try this:

http.onreadystatechange = updatePage(temp);

function updatePage(v) {
return something {

}
hope its help
[ November 24, 2006: Message edited by: Saif uddin ]

Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Originally posted by Venkatraman Kandaswamy:
you can make the variables that you want to pass as global variables.


What a horrible suggestion!


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

You cannot change what somebody else's code is going to pass to the callback function. You need to write your callback to adhere to the signature that the calling code will use.

In this case, the callback function is defined to accept the XMLHttpRequest instance. Normally, you could add your data as properties onto that object to "tag along" for the ride, but because IE6 implements it as an ActiveX object, you can't do this in this case.

Rather, use a closure:


[ November 24, 2006: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [Ajax] if callback function has parameters?