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

Ajax and IE6

Hi all,

I've seen a lot of ajax examples on the web that used an event handler
called 'processChange' for the onreadystatechange event. Normally,
this looks like this:

if(window.XMLHttpRequest) obj = new XMLHttpRequest();
else if(window.ActiveXObject) obj = new
ActiveXObject('Microsoft.XMLHTTP');

obj.onreadystatechange = processChange;
....

function processChange(){
if(obj.readystate != 4) return;
if(obj.status == 200){
// do something
}
}

Well, this works on IE6 and Firefox, but I would like to use this
instead of obj inside of the processChange function (this.readystate
and this.status). This works fine on firefox, but on IE6 it doesn't.
Can someone tell me why?

For the record, I want to use this instead of obj because I want to
make a series of request with a for loop and since happens all inside
of the same closure, obj would refer to the last instance of my
xmlhttprequest.

Thanks,

Vincent
Jul 21 '08 #1
4 1557
On Jul 22, 3:41*am, Vincent <vincentdeh...@gmail.comwrote:
if(window.XMLHttpRequest) obj = new XMLHttpRequest();
else if(window.ActiveXObject) obj = new
ActiveXObject('Microsoft.XMLHTTP');

obj.onreadystatechange = processChange;
...

function processChange(){
* *if(obj.readystate != 4) return;
* *if(obj.status == 200){
* *// do something
* *}

}
<snip>
For the record, I want to use this instead of obj because I want to
make a series of request with a for loop and since happens all inside
of the same closure, obj would refer to the last instance of my
xmlhttprequest.
Rather than using 'this', which changes meaning depending on the
context where the code gets executed, there is another trick you can
use to avoid creating a closure: pass the value of obj instead of
using obj directly.

/* function generator allowing us to pass
* the xmlhttprequest object rather than
* create a closure:
*/
function makeProcessChangeHandler (ajaxObj) {
/* admittedly, it is still a closure
* only in a different scope
*/
return function () {
if(ajaxObj.readystate != 4) return;
if(ajaxObj.status == 200){
// do something
}
}
}
obj.onreadystatechange = makeProcessChangeHandler(obj);
Jul 22 '08 #2
On Jul 22, 12:40 pm, slebetman wrote:
<snip>
... , there is another trick you can use to avoid
creating a closure: pass the value of obj instead of
using obj directly.

/* function generator allowing us to pass
* the xmlhttprequest object rather than
* create a closure:
*/
function makeProcessChangeHandler (ajaxObj) {
/* admittedly, it is still a closure
* only in a different scope
*/
return function () {
if(ajaxObj.readystate != 4) return;
if(ajaxObj.status == 200){
// do something
}
}}

obj.onreadystatechange = makeProcessChangeHandler(obj);
That is creating a closure.
Jul 22 '08 #3
On Jul 22, 1:40*pm, slebetman <slebet...@gmail.comwrote:
>
Rather than using 'this', which changes meaning depending on the
context where the code gets executed, there is another trick you can
use to avoid creating a closure: pass the value of obj instead of
using obj directly.

/* function generator allowing us to pass
** the xmlhttprequest object rather than
** create a closure:
**/
function makeProcessChangeHandler (ajaxObj) {
* /* admittedly, it is still a closure
* ** only in a different scope
* **/
* return function () {
* * if(ajaxObj.readystate != 4) return;
* * if(ajaxObj.status == 200){
* * // do something
* * }
* }}

obj.onreadystatechange = makeProcessChangeHandler(obj);
Yeah !
Other objects and data could be captured as needed in that same
closure as well :

xhr.onreadystatechange = (function (xhr, object, data) {
return function () {

//xhr, object, and data have been captured in the closure.

}
})(xhr, someOtherObject, i);
"auto-reposting, closurized, xhr monitor and exerciser"
http://tinyurl.com/6mm5tm :-)

--Jorge.
Jul 22 '08 #4
On Jul 22, 5:40*pm, Jorge <jo...@jorgechamorro.comwrote:
>
"auto-reposting, closurized, xhr monitor and exerciser"
http://tinyurl.com/6mm5tm :-)
>
BTW, FF3 now seems to handle 6 simultaneous requests...
Safari, Opera: 4
FF2: 2
etc: 2

--Jorge.
Jul 22 '08 #5

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

Similar topics

11
by: Yarco | last post by:
I want to use "Ajax" to create my web for hobby. But i don't know whether "Ajax" is mature... And what about with php? Someone have experience on it? ....
4
by: bobzimuta | last post by:
I'm creating a simple AJAX library. It's an object that will return an array containing the response text or xml. I'm trying to find a way to assign the response as a property of the object, but...
0
by: melledge | last post by:
Ajax Developers' Day added to XTech 2006 agenda XTech 2006 - 17-19 May - Hotel Grand Krasnopolsky - Amsterdam, The Netherlands
0
by: melledge | last post by:
Ajax Developers' Day to Kick Off XTech 2006 Conference Industry experts offer insight into next generation of the Web ALEXANDRIA, VIRGINIA, USA - April 25, 2006 - In response to the rapidly...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
10
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
controlsPlease could some of you here post some of your live examples of AJAX (esp drag panels, collapsable panels, and popup menu.) (It's one thing to talk about how great something is, but it's...
2
by: soni2926 | last post by:
hi, does anyone know of any good books on ajax and asp.net, one that teaches ajax itself before jumping in atlas? I wanted to get an understanding of ajax and how to use it, most books i've seen...
1
by: shaunwo | last post by:
I'm an AJAX / DOM Novice (at best) and trying to figure out how to write the value to a couple input fields. I don't remember exactly where I got the ajax.js file I'm using from (went to the website...
11
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have run into a situation that if a page/tab that uses the Ajax toolkit (using .net version 3.5) is closed before the Ajax enable controls complete loading, then IE locks up. Does it in both IE7...
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...
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...
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
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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...

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.