473,597 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:tru e, onSuccess: function(reques t) {
ajaxFillSelectH TML(request.res ponseText, cmd)}, onFailure:
function(reques t) { 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 20062
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(erro r, 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:tru e,
onSuccess: function(reques t) {
return ajaxFillSelectH TML(request.res ponseText, cmd);
},
onException: function(req,ex ception) {
alert("The request had a fatal exception thrown.\n\n" +
exception);
return true;
},
onFailure: function(reques t) {
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.c om 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:tru e, onSuccess: function(reques t) {
ajaxFillSelectH TML(request.res ponseText, cmd)}, onFailure:
function(reques t) { 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(erro r, 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:tru e,
onSuccess: function(reques t) {
return ajaxFillSelectH TML(request.res ponseText, cmd);
},
onException: function(req,ex ception) {
alert("The request had a fatal exception thrown.\n\n" +
exception);
return true;
},
onFailure: function(reques t) {
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.c om 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:tru e, onSuccess: function(reques t) {
ajaxFillSelectH TML(request.res ponseText, cmd)}, onFailure:
function(reques t) { 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.c om 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(erro r, 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:tru e,
onSuccess: function(reques t) {
return ajaxFillSelectH TML(request.res ponseText, cmd);
},
onException: function(req,ex ception) {
alert("The request had a fatal exception thrown.\n\n" +
exception);
return true;
},
onFailure: function(reques t) {
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.c om 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:tru e, onSuccess: function(reques t) {
ajaxFillSelectH TML(request.res ponseText, cmd)}, onFailure:
function(reques t) { 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.transpo rt.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 showFailureMess age(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.c om 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.transpo rt.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 showFailureMess age(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
3000
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 new to OOP javascript so could be (and probably am) overlooking some detail. Below is the logic of what i'm trying to do. //Javascript code var myClass = Class.create(); myClass.prototype={ initialize: function(fm) {
5
4180
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
2542
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 far, because of the level of abstraction, i guess i would need to edit the prototype.js file? <script type="text/javascript" src="includes/javascript/prototype.js">
4
7693
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 Ajax.Request( url, {method: 'post', parameters: params, onComplete: evalInfo }); function evalInfo( request ) { // do stuff with request
3
3574
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: Ajax.Base = function() {}; Ajax.Base.prototype = { setOptions: function(options) { <...>
3
2068
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 several Ajax.Request calls to gather data from the server. What I'm having trouble with is getting the data from the Ajax call back to the custom class instance. I basicially want to get a Javascript array from my PHP page and insert that into the...
3
4332
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 Prototype's Ajax.Request method like so: function resizetext(size) { new Ajax.Request('resize.php', {method: 'get', parameters: {style: size} }); }
3
1597
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 screen. This element is positioned absolute and uses the clonePosition to get the coords from its caller (_parent) and then adds an offset to prevent overlap. This function works. function relocateTooltip(_tooltip, _parent, _order) { // OffSet...
0
7981
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8284
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8262
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1245
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.