473,387 Members | 1,342 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,387 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 22473


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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.