CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2003
    Location
    London
    Posts
    198

    onReadyStatechange not being called

    I am usinng the following code to send an email
    The code works fine in IE but in Mozilla the function readyStateChanged doesnt get a call back, therefore the user doesnt get the message box saying that his message is sent..
    I placed an alert as a first line in that function, It gets called properly in IE but not in Mozilla... any ideas,
    Thanks,
    Ahmed


    Code:
     var xhReq;
     function createXMLHttpRequest() {
       try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
       try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
       try { return new XMLHttpRequest(); } catch(e) {}
       alert("XMLHttpRequest not supported");
       return null;
     }
    
    function readyStateChanged() {
    //alert("RS called with state:"+xhReq.readyState);
    
     
    
         if (xhReq.readyState != 4)  { return; }
     
         if (xhReq.status != 200)  {
    		alert("Ooops, I was unable to send your message \nIs your internet properly working???");
                return;
         }
         var serverResponse = xhReq.responseText;
    	 
    	alert("Cool! Your message Is gone into my inbox, I will look it as soon as possible");
    
    
    
       };
    
    function sendMail(form)
    {
     
    
     xhReq = createXMLHttpRequest();
    try { 
     
     
    xhReq.open("GET", "http://www.blabla.com/mailproxy.php?comments="+form.comments.value+"&realname="+form.name.value+"&email="+form.email.value, false);
    
    
    } catch (e) {
    alert("Problem occured sending your message..:");
    
    }
    
     
     xhReq.onreadystatechange = readyStateChanged;
     xhReq.send(null);
    }
    Last edited by PeejAvery; September 27th, 2007 at 11:39 AM.
    He is not strong and powerful, who throws people down, but he is strong who withholds himself from anger
    MyWeb

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: onReadyStatechange not being called

    It probably isn't working because of the createXMLHttpRequest() function. Try...

    Code:
    function createXMLHttpRequest(){
      var xmlHTTP;
      try{xmlHTTP = new XMLHttpRequest();}
      catch(e){
        try{xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");}
        catch(e){
          try{xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");}
          catch(e){
            alert("Your browser does not support AJAX!");
            return false;
          }
        }
      }
      return xmlHTTP;
    }
    Your code could use some clean up. Check out my AJAX object for more help.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Mar 2003
    Location
    London
    Posts
    198

    Re: onReadyStatechange not being called

    I tried this but same result for Mozilla firefox.
    He is not strong and powerful, who throws people down, but he is strong who withholds himself from anger
    MyWeb

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: onReadyStatechange not being called

    Use my AJAX object instead. I use it with 5+ browsers.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Mar 2003
    Location
    London
    Posts
    198

    Re: onReadyStatechange not being called

    I've used your script.
    I figured out the problem ,
    I was using synchonous call to open.
    but why should synchronous call not let state change call backs in Mozilla but in IE .!!!
    seems funny..
    I was using synchronous call to avoid user to press the message send button again and again...
    Now i am using asynchrnous call and asking the user to wait through UI.
    He is not strong and powerful, who throws people down, but he is strong who withholds himself from anger
    MyWeb

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: onReadyStatechange not being called

    Mine is also set to do synchronous...unless you changed it.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Mar 2003
    Location
    London
    Posts
    198

    Re: onReadyStatechange not being called

    Yours is set to asynchronous, and thst how i figured out prolem in my code..

    XMLHttpRequest.open(sMethod, sUrl [, bAsync] [, sUser] [, sPassword])
    you've passed true, isnt it or did i get code from wrong place ?!

    I got code from your website, this ciode.
    Last edited by PeejAvery; September 28th, 2007 at 07:08 AM. Reason: Removed code and replaced with link.
    He is not strong and powerful, who throws people down, but he is strong who withholds himself from anger
    MyWeb

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: onReadyStatechange not being called

    Ha. I forgot that I changed that on the website. I used to have it set to synchronous.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  9. #9
    Join Date
    Mar 2003
    Location
    London
    Posts
    198

    Re: onReadyStatechange not being called

    Thanks alot for the help
    He is not strong and powerful, who throws people down, but he is strong who withholds himself from anger
    MyWeb

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: onReadyStatechange not being called

    You're most welcome! Good luck.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured