Ajax.Request bug using IE 7 and Prototype 1.7

343 views
Skip to first unread message

A.B.

unread,
Dec 1, 2010, 11:04:13 AM12/1/10
to Prototype & script.aculo.us
Hello everbody!
I want to tell you about a "funny" error I've found making an
Ajax.Request with Internet Explorer 7 and Prototype 1.7.
Please. considering this very standard code:

function ajaxCall(url, callbackResponse) {
try{
new Ajax.Request(url, {
method: 'get',
asynchronous: true,
onSuccess: function(transport) {
callbackResponse_1();
callbackResponse_2();
}
});
} catch (exception) {
alert(exception.inspect());
}
}

When trying to execute those lines the Ajax.Request never happened,
not only the callback method, even the very first
"transport.send(url)" never starts. Googling and debugging a bit, I've
found out the root of my problem:

Basically the cause of bug is the well know poor designed
XMLHttpRequest implementation of IE7 which is really buggy ad won't
work as we expected. Anyway there's is also a prototype issue. In fact
in version 1.7 sources there are these lines of code:

var Ajax = {
getTransport: function() {
return Try.these(
function() {return new XMLHttpRequest()},
<-------------------------------
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
) || false;
},

[......]

that try to create XMLHttpRequest object in a "browser-compatibility"
way. Anyway because IE7 supports XMLHttpRequest, but it's buggy, those
lines force it to use a buggy implementation instead of less-good-but-
working Activex one.
I wouldn't call it a "prototype bug" but it's a fact that at least one
old version (I've seen it on 1.4) had a slightly different
implementation:

var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
function() {return new ActiveXObject('Microsoft.XMLHTTP')},
function() {return new XMLHttpRequest()}
<-------------------------------
) || false;
},

which perfectly works with different browser (IE 7/8, FF3, Chrome for
sure).

I hope that my post will be of help for someone else.

Best Regards.

T.J. Crowder

unread,
Dec 1, 2010, 6:05:30 PM12/1/10
to Prototype & script.aculo.us
Hi,

Your code, as quoted, assumes that the symbols `callbackResponse_1`
and `callbackResponse_2` are defined by a scope enclosing your
ajaxCall function, as the code you quoted doesn't define them anywhere
but the `onSuccess` handler tries to call them. When those symbols are
defined (http://jsbin.com/asate3), the code works (including on IE7).
When they aren't defined (http://jsbin.com/asate3/2), it fails (with
all the browsers I tested -- Chrome, Mozilla, Opera, IE6, IE8...),
which makes sense as you're trying to call functions that don't exist.
If you set it up to actually call the `callbackResponse` passed into
it (http://jsbin.com/asate3/3), it succeeds in calling that (including
on IE7) and then fails (of course) to call the non-existant function
callbackResponse_1.

Nothing whatsoever to do with XMLHttpRequest. Or Prototype.

Am I missing something?
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

A.B.

unread,
Dec 2, 2010, 9:24:42 AM12/2/10
to Prototype & script.aculo.us
Sorry, you're right. the code posted is incorrect. the right one is:

function otherFunc(o){
[.....]
};

function ajaxCall(url, callbackResponse_1, p) {
try{
new Ajax.Request(url, {
method: 'get',
asynchronous: true,
onSuccess: function(transport) {
otherFunc(p);
callbackResponse_1();
}
});
} catch (exception) {
alert(exception.inspect());
}

}

..anyway onSucces never got reached because Ajax.request simply die
after onCreate().To be more precise I had a JSP page including three
<script> tag:
<script>prototype.js</script>
<script>ajaxCall.js</script>, which contains the ajaxCall() and the
otherFunc() functions above.
<script>{inline_script}</script>, which contains a function "search()"
that calls ajaxCall(url,callbackResponse_1,p) and, of course, function
callbackResponse_1() itself.
After that there's an anchor in the page's form with
"javascript:search();" in its onClick attribute.

Please consider that I didn't write this page by myself (..I think,
for other thousands good reasons, that it is really a messy JSP!!!)
I'm just bugfixing it.

The fact is that the page won't work if simply import prototype.js on
IE7 (7.0.5730.13), but it works on FF (3.6.12) and IE 8. The only ways
that I found out to get it work are:
- moving "function() {return new XMLHttpRequest()" and the end of the
Try.these statement in prototype code (it works in ANY browser i
tried).
- disable "native XMLHttpRequest support" from IE7 advanced options
(but as you easily understand I can't force users to disable a browser
option to use my page.. :-| ).

Any other suggestion?


On 2 Dic, 00:05, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi,
>
> Your code, as quoted, assumes that the symbols `callbackResponse_1`
> and `callbackResponse_2` are defined by a scope enclosing your
[.....]

T.J. Crowder

unread,
Dec 2, 2010, 1:15:02 PM12/2/10
to Prototype & script.aculo.us
Hi,

> Sorry, you're right. the code posted is incorrect. the right one is:

I haven't bothered to try it, but I'm not seeing anything in that code
that would pose a problem.

Unless you can put together a minimal, self-contained example, I don't
think anyone is going to be able to help you. I don't think the fact
it's JSP has anything to do with it (unless, of course, the JSP isn't
outputting the HTML you expect -- but that's nothing to do with
Prototype).

> Any other suggestion?

Just to create a self-contained example and post it somewhere.

Good luck,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

Reply all
Reply to author
Forward
0 new messages