Hello all,
   I am using the Ajax.Request (Prototype version 1.5.0 rc0) method in
a JSP file that I am having trouble with.  The trouble is that it does
not always send a request to the server and the onFailure callback is
called.  Here is the code for the request:
new Ajax.Request("ProcessAttachedStructures_TC", {  //Servlet is
properly mapped.
	asynchronous: true,
	method: "post",
	parameters: parameters,  //I am sure params are correct
	onSuccess: function(request) {
			$(''attStructMsgDiv'').innerHTML = " ";
		        $(''attStructContent'').innerHTML =
request.responseText;  //
HTML returned
			$(''GC_USER_TEXT_1A'').focus();
	},
	onFailure: function(request) {
			$(''attStructContent'').className = "redNotice";
			$(''attStructContent'').innerHTML = "Could not connect
to server,
please try again later or contact the OMIG Service Center.";
			$(''attStructContent'').innerHTML +=
"<br><br>" +
request.responseText;
	},
	onException: function(req,exception) { alert(exception); }
});
I put breakpoints on the first line of the doGet() and doPost()
methods of the ProcessAttachedStructures_TC servlet.  The doGet() is
called several times by other Ajax.Requests on the page, but the POST
request above does not always get sent to the servlet (the doPost()
method is never called).  The onFailure() function is called though
and nothing is in the request.responseText field.  This works fine in
IE7 and FireFox 2, but rarely works in IE6.
However, if I change the code slightly to retry the request multiple
times, I get more success.  Here is the modified code:
var attempts = 0;
...
new Ajax.Request("ProcessAttachedStructures_TC", {  //Servlet is
properly mapped.
	asynchronous: true,
	method: "post",
	parameters: parameters,  //I am sure params are correct
	onSuccess: function(request) {
			$(''attStructMsgDiv'').innerHTML = " ";
		        $(''attStructContent'').innerHTML =
request.responseText;  //
HTML returned
			$(''GC_USER_TEXT_1A'').focus();
                        $(''attStructMsgDivTest'').innerHTML
"Successful save after " + attempts + " attempts.";
			attempts = 0;
	},
	onFailure: function(request) {
                        if( attempts <= maxAttempts ) {
	  			attempts++;
	  			$(''attStructMsgDivTest'').innerHTML += "Attempt
#" + attempts +
"<br>";
	  			saveAttachedStructure();  //the function we''re in now.
	  		}
	  		else {
                               
$(''attStructContent'').className "redNotice";
			        $(''attStructContent'').innerHTML = "Could not
connect to
server, please try again later or contact the OMIG Service Center.";
			        $(''attStructContent'').innerHTML +=
"<br><br>" +
request.responseText;
                        }
	},
	onException: function(req,exception) { alert(exception); }
});
The added code serves the purpose of trying the request up to three
times if the onFailure function is called.  In IE6 I generally find
that it takes one or two attempts to get the request to actually reach
the server.  Nonetheless, my users are reporting that it still
completely fails at times.
I have tried using newer versions of Prototype, but that does not
change the result.  The most puzzling part to me is that neither
version of the code works 100% of the time for IE6.  I use the
Ajax.Request object in other places and do not experience this problem
there.  I searched through this message group and didn''t find anything
that solved my problem.  Does anyone have a clue at what I''m doing
wrong here?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---