By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,665 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,665 IT Pros & Developers. It's quick & easy.

Prototype: Ajax.Request - onFailure not working for me in IE6

P: n/a
I'm trying to handle the scenario where a user's session times out and
and their ajax request triggers a redirection by the webserver (302
error?).

I'm using Prototype 1.4 and the my works great with Firefox,but with
IE6 the onFailure never gets called and the request never completes.

My code:

var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
params,
evalScripts:true, onSuccess: function(request) {
ajaxFillSelectHTML(request.responseText, cmd)}, onFailure:
function(request) { reloadPage()}});

As an alternative I'm thinking about setting a page timout that is
cancelled when the Ajax request completes, but I was hoping that there
was a better way...

Jun 6 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Does it throw an exception? Is the request being received by the server
and passed back properly and then just not being processed by IE's JS
engine?

Try doing this just to see if there is a bug somewhere.

window.onerror = trap_error;

function trap_error(error, url, line) {
alert("There was an error from '" + url + "' at line '" + line +
"'.\n\n" + error);
return true;
}

Also add this to your Ajax.Request parameters:

var ajaxReq = new Ajax.Request(
url,
{
method: 'post',
parameters: params,
evalScripts:true,
onSuccess: function(request) {
return ajaxFillSelectHTML(request.responseText, cmd);
},
onException: function(req,exception) {
alert("The request had a fatal exception thrown.\n\n" +
exception);
return true;
},
onFailure: function(request) {
return reloadPage();
}
}
);

Prototype has a few different events for the Ajax requests. If IE is
pooping out, try doing something for all of them. You may want to look
at onComplete as a possible option. onException is supposed to get
thrown if there is a javascript error somewhere. If you're passing back
scripts to be evaluated, IE's js interpretter may just be throwing an
exception that you're not trapping, so it gets discarded with no
warning. Definitely something to look into.

If you're still having trouble, please write back. You can even send me
an email if you want. Definitely let us all know how this turned out
though.

-E

do*****@gmail.com wrote:
I'm trying to handle the scenario where a user's session times out and
and their ajax request triggers a redirection by the webserver (302
error?).

I'm using Prototype 1.4 and the my works great with Firefox,but with
IE6 the onFailure never gets called and the request never completes.

My code:

var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
params,
evalScripts:true, onSuccess: function(request) {
ajaxFillSelectHTML(request.responseText, cmd)}, onFailure:
function(request) { reloadPage()}});

As an alternative I'm thinking about setting a page timout that is
cancelled when the Ajax request completes, but I was hoping that there
was a better way...


Jun 7 '06 #2

P: n/a
Eric,

Thanks for taking the time to post your suggestions.

I like the onException bit, that helped this morning when I had a typo
in my javascript.

The part that I'm still wrestling with is handling the 302 error. When
I manually kill my session (there's an eRights authentication plug-in
on our apache webserver), Firefox responds perfectly to "onFailure" and
even "on302" reporting a request.status of "302").

in IE6, on the other hand, nothing is getting triggered: onSuccess,
onComplete, onException, onFailure, on302.

This might be related the multiple redirects that happen when a user
session expires in our application and might be complicated by the
configuration of our development environment.

For now, I think I'll look at setting a timeout on the request.

I'll let you know if I learn anything more,

Doug





Eric Ryan Harrison wrote:
Does it throw an exception? Is the request being received by the server
and passed back properly and then just not being processed by IE's JS
engine?

Try doing this just to see if there is a bug somewhere.

window.onerror = trap_error;

function trap_error(error, url, line) {
alert("There was an error from '" + url + "' at line '" + line +
"'.\n\n" + error);
return true;
}

Also add this to your Ajax.Request parameters:

var ajaxReq = new Ajax.Request(
url,
{
method: 'post',
parameters: params,
evalScripts:true,
onSuccess: function(request) {
return ajaxFillSelectHTML(request.responseText, cmd);
},
onException: function(req,exception) {
alert("The request had a fatal exception thrown.\n\n" +
exception);
return true;
},
onFailure: function(request) {
return reloadPage();
}
}
);

Prototype has a few different events for the Ajax requests. If IE is
pooping out, try doing something for all of them. You may want to look
at onComplete as a possible option. onException is supposed to get
thrown if there is a javascript error somewhere. If you're passing back
scripts to be evaluated, IE's js interpretter may just be throwing an
exception that you're not trapping, so it gets discarded with no
warning. Definitely something to look into.

If you're still having trouble, please write back. You can even send me
an email if you want. Definitely let us all know how this turned out
though.

-E

do*****@gmail.com wrote:
I'm trying to handle the scenario where a user's session times out and
and their ajax request triggers a redirection by the webserver (302
error?).

I'm using Prototype 1.4 and the my works great with Firefox,but with
IE6 the onFailure never gets called and the request never completes.

My code:

var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
params,
evalScripts:true, onSuccess: function(request) {
ajaxFillSelectHTML(request.responseText, cmd)}, onFailure:
function(request) { reloadPage()}});

As an alternative I'm thinking about setting a page timout that is
cancelled when the Ajax request completes, but I was hoping that there
was a better way...


Jun 7 '06 #3

P: n/a

do*****@gmail.com wrote:
Eric,

Thanks for taking the time to post your suggestions.

I like the onException bit, that helped this morning when I had a typo
in my javascript.
Yeah, those onException things are wonderful. I don't know what kind of
development environment you have, but I've found it most useful to
create a small development/debugging console for all of my pages that
those exceptions and warnings get dumped to. I can quickly rundown and
trace errors as they come up. Then for my userbase I merely use a
different function for their errors. Some errors I trap quietly and
other errors I display alerts to the user. It just depends on the
situation.

You may want to look into Ajax.Responders. I've not used it myself yet,
but if what I read is correct, you can configure all of your ajax
requests to function the same way by adding stuff to Ajax.Responders.From what I've read, it seems like for something like onException, you'd be able to put that into Ajax.Responders one time and then have
every one of your Ajax requests use that onException. Might save you
some time and might cut down on code doing the same thing appearing
everywhere you do a request.

The part that I'm still wrestling with is handling the 302 error. When
I manually kill my session (there's an eRights authentication plug-in
on our apache webserver), Firefox responds perfectly to "onFailure" and
even "on302" reporting a request.status of "302").

in IE6, on the other hand, nothing is getting triggered: onSuccess,
onComplete, onException, onFailure, on302.

This might be related the multiple redirects that happen when a user
session expires in our application and might be complicated by the
configuration of our development environment.

That may be entirely possible. To be completely honest with you, I've
never seen an ajax implementation responding to 302. Here at work where
we make heavy use of all kinds of insanely complicated ajax hackery, we
still try to completely avoid any and all server things like this if we
can.

We nicely handle 404's and 500's, but everything else we avoid like the
plague.

Given the information that Firefox runs the 302 stuff fine and IE is
the one that just dies, it would seem that this is another IE
shortcoming. I've not read anything about it yet anywhere on the
internet, so you may be the first person to discover this flaw. Might
be in everyones best interest to document the flaw and publish your
findings on a blog or something somewhere. Remember that strictly
speaking, IE 6 and below are using a retarded ActiveX object for it's
XHR stuff. If looking at their ActiveX implementation of standard HTML
select boxes is any indication, I wouldn't be surprised if it was
choking on the 302 and then not informing the js interpretter that an
error occurred.
For now, I think I'll look at setting a timeout on the request.

I'll let you know if I learn anything more,

Good luck. I appreciate it. This is an interesting problem and has a
lot of implications for future development ( for those of us who HAVE
to support IE ). I hope you can find a workaround without too much
hackery.

-E
Doug





Eric Ryan Harrison wrote:
Does it throw an exception? Is the request being received by the server
and passed back properly and then just not being processed by IE's JS
engine?

Try doing this just to see if there is a bug somewhere.

window.onerror = trap_error;

function trap_error(error, url, line) {
alert("There was an error from '" + url + "' at line '" + line +
"'.\n\n" + error);
return true;
}

Also add this to your Ajax.Request parameters:

var ajaxReq = new Ajax.Request(
url,
{
method: 'post',
parameters: params,
evalScripts:true,
onSuccess: function(request) {
return ajaxFillSelectHTML(request.responseText, cmd);
},
onException: function(req,exception) {
alert("The request had a fatal exception thrown.\n\n" +
exception);
return true;
},
onFailure: function(request) {
return reloadPage();
}
}
);

Prototype has a few different events for the Ajax requests. If IE is
pooping out, try doing something for all of them. You may want to look
at onComplete as a possible option. onException is supposed to get
thrown if there is a javascript error somewhere. If you're passing back
scripts to be evaluated, IE's js interpretter may just be throwing an
exception that you're not trapping, so it gets discarded with no
warning. Definitely something to look into.

If you're still having trouble, please write back. You can even send me
an email if you want. Definitely let us all know how this turned out
though.

-E

do*****@gmail.com wrote:
I'm trying to handle the scenario where a user's session times out and
and their ajax request triggers a redirection by the webserver (302
error?).

I'm using Prototype 1.4 and the my works great with Firefox,but with
IE6 the onFailure never gets called and the request never completes.

My code:

var ajaxReq = new Ajax.Request( url, {method: 'post', parameters:
params,
evalScripts:true, onSuccess: function(request) {
ajaxFillSelectHTML(request.responseText, cmd)}, onFailure:
function(request) { reloadPage()}});

As an alternative I'm thinking about setting a page timout that is
cancelled when the Ajax request completes, but I was hoping that there
was a better way...


Jun 9 '06 #4

P: n/a
Eric,

I ended up using the solution posted in the url below to set a default
"time-out" for all prototype ajax requests. It's working for me now:

http://codejanitor.com/wp/2006/03/23...ith-prototype/

Basically, if nothing happens for X seconds the request is killed:

request.transport.abort();

and then the onFailure handler is called and I use the prototype
Try.these bit to trap the status if there is one:

function showFailureMessage(request) {

var status = Try.these(
function() { return request.status },
function() { return 'timed out'}
)

alert ('There was a problem: status(' + status + ');

etc.

Again, thanks for your help/interest in my issue,

Doug

Jun 9 '06 #5

P: n/a

do*****@gmail.com wrote:
Eric,

I ended up using the solution posted in the url below to set a default
"time-out" for all prototype ajax requests. It's working for me now:

http://codejanitor.com/wp/2006/03/23...ith-prototype/

Basically, if nothing happens for X seconds the request is killed:

request.transport.abort();

and then the onFailure handler is called and I use the prototype
Try.these bit to trap the status if there is one:

function showFailureMessage(request) {

var status = Try.these(
function() { return request.status },
function() { return 'timed out'}
)

alert ('There was a problem: status(' + status + ');

etc.

Again, thanks for your help/interest in my issue,
No problem man. Don't hesitate to come back with any other problems you
have in the future. I learn best by hacking at problems, so you're
really doing ME a favor by letting me poke away at problems you have.

-E
Doug


Jun 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.