Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2007, 09:56 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Mozilla onreadystatechange incompatibility

Okay, I'm fried... I've been hammering on this for days and I can't figure it out... Code's going all spaghetti on me...

This works in IE but updates do not happen in Mozilla 2.0.0.6.

Scriptaculous library (1.7.1_beta3), Prototype (1.6.0_rc0) and zXML 1.0.2 are being used. Scriptaculous is being used to autopopulate a field. Once that field is selected, an updateElement call is made to "getData" (this function). This function then goes and fires a whole bunch of asychronous calls to the server to load data.

In IE, it gets all of the way through it... In Moz 2.0.0.6 it never gets into the onreadystate function even though the readystate does change from 1 to 4 and it does get a status of 200.

My guess is that the event is never getting called in Mozilla so it's never getting into the oXmlHttp.onreadystatechange function.

Ideas?

THanks!



Code:
  function getData(fullAddress)
   {
    var fullAddressElement = document.getElementById("fullAddress");
    fullAddressElement.value = fullAddress.innerHTML;

    whereFieldElement = document.getElementById("whereField");

    var whereField = whereFieldElement.value;

    for (var x = 0; x <= document.dataEntry.length-1; x++)
     {
      var getElement = document.getElementById(document.dataEntry.elements[x].name);
      var get = getElement.name;
      var where = whereField + "='"+ fullAddressElement.value +"'";

      var oXmlHttp = zXmlHttp.createRequest();
      oXmlHttp.open("GET", "getValue.php?get=" + get + "&where=" + where, false);
           alert (oXmlHttp.readyState);
      oXmlHttp.onreadystatechange = function ()
       {
        if (oXmlHttp.readyState == 4)
         {
          alert ("in state -"+ oXmlHttp.readyState +"-");
          if (oXmlHttp.status == 200)
           {
            getElement.value = oXmlHttp.responseText;
           }
          else
           {
            alert ("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
           }
         }
       };
           alert (oXmlHttp.readyState);

      oXmlHttp.send(null);
           alert (oXmlHttp.readyState);
           alert (oXmlHttp.status);
     }
   }
 
Old August 20th, 2007, 10:22 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

You normally use onreadystatechange with an async call, have you tried setting the third parameter of the open method to true?

--

Joe (Microsoft MVP - XML)
 
Old August 20th, 2007, 11:38 AM
Registered User
 
Join Date: Aug 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Joe,

I left it async and removed the event capture and it works in IE and Moz. Question...

If I do it sync in Mozilla, and I slow it down with the alerts, it works. If I do not slow it down, it only gets the last one...

Why is that? Is there something I don't understand about event capture? Is it funky in Moz?

Thanks!

 
Old August 21st, 2007, 02:04 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If I recall correctly Mozilla/Gecko doesn't natively support all the states that IE does, zXml tries to emaulate it but it can only really be completed or not. The normal pattern for Ajax is to use an asynchronous call, otherwise it would be called Sjax :)

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
incompatibility of versions. Vilariño ASP.NET 1.0 and 1.1 Basics 0 March 8th, 2007 09:52 AM
Browszer incompatibility neuropathie ASP.NET 1.0 and 1.1 Professional 1 July 11th, 2006 07:44 AM
pasteHTML() for mozilla ? Farooq Javascript 0 December 21st, 2005 07:39 AM
Incompatibility Linux-Windows jguillen Pro PHP 3 April 19th, 2005 06:49 AM
MSXML2.XMLHTTP40. OnReadyStateChange won't work LarryT Access VBA 0 August 8th, 2004 05:28 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.