• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Ajax] if callback function has parameters?

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can make the variables that you want to pass as global variables.
 
Muhammad Saifuddin
Ranch Hand
Posts: 1324
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Venkatraman Kandaswamy:
you can make the variables that you want to pass as global variables.


What a horrible suggestion!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic