[Javascript] Firefox 1.5+ and Ajax responses

Bosky, Dave Dave.Bosky at htcinc.net
Mon Oct 2 07:37:18 CDT 2006


I've got an AJAX enabled page which sends a few parameters to a Servlet
and returns a simple 'Y or N' back to the page.

For some reason in Firefox 1.5 the 'readystate' parameter seems to
undefined, my 'onreadystatechange' function checks the 'readystate' for
a value of '4' but firefox never sets it to 4.

So nothing happens. 

 

I've installed the Firebug plugin to examine the http headers. It shows
my parameters got sent to the servlet, it shows a response value of 'Y
or N' and the header information all looks correct but nothing happens
in Firefox. Of course everything works fine in Internet Explorer.

 

Code snippets below.

 

Thanks,

Dave

 

 

<!-- JS Functions -->

function createRequest() {           

            if (!request && typeof XMLHttpRequest != 'undefined') {

                        try {

                                    request = new XMLHttpRequest();

                        } catch (e) {

                                    alert("Your browser is not
supporting XMLHTTPRequest");

                                    request = false;

                        }

            }  else if (window.ActiveXObject) {

                        var aVersions = [ "MSXML2.XMLHttp.5.0",
"MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp",
"Microsoft.XMLHttp" ];

                        for (var i = 0; i < aVersions.length; i++) {

                                    try {

                                                request = new
ActiveXObject(aVersions[i]);

                                    } catch (oError) {}

                        }

            }

            return request;

}

function confirmSelectedServices(total) {

                        var request = createRequest();

 
request.open("get","/servlet/validate?items="+total);

                        request.onreadystatechange = function() {

                        if (request.readystate == 4) {

                                    if (request.status == 200)  {

                                    var msg = request.responseText;

                                    }

                        }

}

 

<!-Servlet snippet -->

String status = "Y";

response.setContentType("text/xml");

response.setHeader("Cache-Control","no-cache");

response.getWriter().write(status);


**********************************************************************
HTC Disclaimer:  The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.  If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.  Thank you.
**********************************************************************

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20061002/711ac5ea/attachment.htm>


More information about the Javascript mailing list