473,323 Members | 1,551 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,323 software developers and data experts.

AJAX onreadystatechange take parameters?

I realize that this may have been asked before, but I could not find a
definitive answer.

function loadXMLDoc(url, MyFunction)
{
// use native XMLHttpRequest object
if (window.XMLHttpRequest) {
request = new XMLHttpRequest();
request.onreadystatechange = MyFunction;
request.open("GET", url, true);
request.send(null);
// use IE/Windows ActiveX version
} else if (window.ActiveXObject) {
request = new ActiveXObject("Microsoft.XMLHTTP");
if (request) {
request.onreadystatechange = MyFunction;
request.open("GET", url, true);
request.send();
}
}
}

Is there any way to script 'MyFunction' aka the callback function to
take parameters?

Feb 23 '06 #1
1 22469


ak*********@gmail.com wrote:

request.onreadystatechange = MyFunction;
Is there any way to script 'MyFunction' aka the callback function to
take parameters?


That assigment simply assigns MyFunction as the onreadystatechange event
handler. You can also dynamically create functions with a function
expression for instance so that you probably want e.g.
request.onreadystatechange = function () {
if (request.readyState == 4) {
MyFunction(arg1, arg2);
}
};
where the onreadystatechange handler is an anonymous function created by
a function expression. That function is then being called by the
implementation of the XMLHTTP request object and in turn can of course
call other functions (like MyFunction) and pass arguments to that.
You should read up on closures then
<http://www.jibbering.com/faq/faq_notes/closures.html>
--

Martin Honnen
http://JavaScript.FAQTs.com/
Feb 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: whreed | last post by:
I am using AJAX XMLhttprequest to request another page on form submit and I am loading that page into a span tag. My issue is that I have more js in the called page that loads a calendar on click...
10
by: lkagan2000 | last post by:
I'm reading 'Ajax in Action', (one of the best of the many tech books I've read) and there's an example that I just don't fully understand. If you happen to have the book, it's on page 75. I'm...
2
by: Mark Knochen | last post by:
Hi, i have a little problem with ajax. The follow functions are in my site: function sndReq(ID,divID) { resObjekt.open('get','inc/inc_change_pagelogo.php?ID='+ID,true);...
17
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
10
by: Daniel Loose | last post by:
hi dear folks, i'm new to ajax. simple request no problem - but it seems when I set the response handler function, I can only pass the function name and not give parameters, so I have a problem...
3
JamieHowarth0
by: JamieHowarth0 | last post by:
Hi folks, I have a bit of a headache. I've finally added all the nice finishing touches to my own website (static only with a bit of DHTML). Now I've just converted the whole thing to AJAX with a...
3
by: gunjan123 | last post by:
Dear Friends , I am new in ajax .Follwoning code give error - var ajaxpack=new Object() ajaxpack.basedomain="http://"+window.location.hostname ajaxpack.ajaxobj=createAjaxObj()...
4
by: slebetman | last post by:
On Jun 5, 9:36 pm, sheldonlg <sheldonlgwrote: You can of course use closure to pass the required parameter: var hideIt; // the variable you wish to pass ajax.onreadystatechange = function () {...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.