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

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

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
5 20033
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
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

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
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
by: bigdadro | last post by:
I've created a new class using prototype.js. After I make the ajax.request all references to this.myClassMethodorVariable are lost. Does the ajax method blow out the object persistance? I'm fairly...
5
by: Gerry Vandermaesen | last post by:
Hi, Does anyone have a freely available JavaScript JSON stringifier. So far my search has been in vain, the one offered on http://www.json.org/json.js does not seem to work for me.
6
by: libsfan01 | last post by:
Hi all Im trying to use prototype for an xmlhttprequest, but it doesn't seem to be working cross-browser. Is there someway of getting it to be IE6 compatible (active x)? here's my code so...
4
by: ext237 | last post by:
Simple ajax call seems to have some issues in Firefox. The "onComplete:" is called BEFORE the response is returned by the call. Is there a coding issue or a work around? var ajax = new...
3
by: jacobstr | last post by:
I've noticed Object.extend used in a few different ways and I'm having trouble distinguishing why certain usages apply to a given situation. On line 804 Ajax.Base is defined as follows: ...
3
by: wendallsan | last post by:
Hi All, I've stumped myself writing an app that uses Prototype and a bit of PHP. Here is what I have: I have a custom class named Default_county_init_data that, upon initialization makes...
3
pezholio
by: pezholio | last post by:
Hi, I'm currently putting together a stylesheet switcher for a project I'm working on, it's a server side solution at the moment, and I'd like to AJAX it up and avoid page reloads. I'm using...
3
Airslash
by: Airslash | last post by:
Hello, currently I have 2 functions thatI'm trying to get to work together. Both functions make use of the Prototype library. The first function moves a div container with ID _tooltip on the...
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
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...

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.