Ajax is not giving response when Firebug is off..........

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rpnew
    New Member
    • Aug 2007
    • 189

    Ajax is not giving response when Firebug is off..........

    Hi,
    I'm facing this problem. I'm developing a tool in PHP/MySql with litle bit use of Ajax. At once place i've used Ajax function for validation purpose . But my problem is when my firebug is off/disabled Ajax dosent show any response and i get the wrong messages. But when firebug is on/enabled then it shows the proper output. What could be the problem?
    If you want to see the code then i can paste it here.


    Regards,
    RP
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Either post the code or a link to a test page.

    Comment

    • rpnew
      New Member
      • Aug 2007
      • 189

      #3
      Originally posted by acoder
      Either post the code or a link to a test page.
      Hi,
      Here is the Ajax code..
      [CODE=javascript]
      <!-- Function for HTTPRequest object-->
      function getHTTPObject()
      {
      var xmlhttp;
      if (window.ActiveX Object)
      {
      try
      {
      xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP" );
      }
      catch (e)
      {
      try
      {
      xmlhttp = new ActiveXObject(" Microsoft.XMLHT TP");
      }
      catch (E)
      {
      xmlhttp = false;
      }
      }
      }
      else
      {
      xmlhttp = false;
      }
      if (window.XMLHttp Request)
      {
      try
      {
      xmlhttp = new XMLHttpRequest( );
      }
      catch (e)
      {
      xmlhttp = false;
      }
      }
      return xmlhttp;
      }

      <!-- Function for checking duplicate names....-->
      function validatenames()
      {
      var htpobj = getHTTPObject() ;
      var str = document.mod_fo rm.Mod_Name.val ue;
      var pname=document. mod_form.Prod_N ame.value
      url='checknames .php?mname='+st r+'&pname='+pna me;
      htpobj.open("GE T", url, false);
      htpobj.onreadys tatechange = function()
      {
      if (htpobj.readySt ate == 4)
      {
      if(htpobj.respo nseText == 1)
      {
      alert(htpobj.re sponseText);
      document.getEle mentById('vlnam es').value=0;
      document.mod_fo rm.Mod_Name.foc us();

      }
      else
      {
      document.getEle mentById('vlnam es').value=1;
      alert(htpobj.re sponseText);
      document.mod_fo rm.Mod_Desc.foc us();
      }
      }
      }
      htpobj.send(nul l);
      }
      [/CODE]

      Here is where i'm calling it....
      [CODE=javascript]
      <!-- Function for checking blank fields....-->
      function validate_form()
      {
      validatenames() ;
      //document.write( document.feat_t ab.width);
      tr=true;
      if(document.mod _form.Prod_Name .value == "")
      {
      tr = false;
      alert('Product Id blank');
      return tr;
      }
      else if(document.mod _form.Mod_Name. value == "")
      {
      tr = false;
      alert('Module Name Field Can\'t Be Blank');
      return tr;
      }
      else if(document.mod _form.vlnames.v alue==0)
      {
      tr=false;
      alert('Duplicat e Module Name Is Not Allowed');
      document.mod_fo rm.Mod_Name.foc us();
      return tr;
      }
      else
      {
      var agre=confirm('a re you sure you want to submit the data???') ;
      if(!agre) return false;
      else
      {
      //refresh_feat_fr ame();
      return true;
      }
      }

      }
      [/CODE]

      And my PHP script just returns 0 and 1 if the name i'm sending to the scipt is present in database or not......

      Now upto this point what i've done and what problem i've faced.....

      As you can see i'm giving Ajax response to one TEXT field which i'm checking in form validation function.. If it has 0 then duplicate name is entered and if it is 1 then it means that user can submit the value.
      Now first i tried the VALIDATENAMES() function itself in IF condition but as i didnt know how return something from Ajax function it was not working(If you can help me with that that would be good as well).
      So what i did is i'm giving Ajax response to one textbox and then checking it for validation purpose.. Now what my problem is.....
      I'm using firebug for javascrip/Ajax debugging.... now i've checked following four cases..

      FireBug Enabled-Synchronuous Request


      • Works fine
      FireBug Disabled-Synchronuous Request
      • No response from Ajax
      FireBug Enabled-Asynchronuous Request
      FireBug Disabled-Asynchronuous Request
      • Late response in both cases
      One more thing i've learned through googling is this happens if you've not used your Ajax functions properly.... So in the last i would like to mention that what i want to do so if there is any another way you can guide me there...
      Here i'm checking users input(name). If it is already there in database user will not be allowed to submit and if it is not there user can enter the value.....

      Regards,
      RP

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        The responseText is a string, so you may want to parse or trim it. You should also check that the status is 200 (OK) before using the responseText.

        Comment

        • rpnew
          New Member
          • Aug 2007
          • 189

          #5
          Originally posted by acoder
          The responseText is a string, so you may want to parse or trim it. You should also check that the status is 200 (OK) before using the responseText.
          Hi,
          I did that even but the problem is same let me write that again......

          FireBug Enabled-Synchronuous Request
          • Works fine
          FireBug Disabled-Synchronuous Request
          • No response from Ajax
          FireBug Enabled-Asynchronuous Request
          FireBug Disabled-Asynchronuous Request
          • Late response in both cases
          So what could be the problem... and one more thing i would like t ask is .. is there any way to return something from Ajax function which we call by Onreadystatecha nge???

          Regards,
          RP

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            The asynchronous requests are working fine - that is expected behaviour. The only time it doesn't seem to work is if Firebug is disabled during a synchronous request.

            Why do you need a synchronous request anyway?

            Comment

            • rpnew
              New Member
              • Aug 2007
              • 189

              #7
              Originally posted by acoder
              The asynchronous requests are working fine - that is expected behaviour. The only time it doesn't seem to work is if Firebug is disabled during a synchronous request.

              Why do you need a synchronous request anyway?
              Well..
              Frankly i've not selected it...... but its only the working condition... as i've mentioned..
              In Asynchronous requests the response are coming late then when i'm expecting...... ..... and thats why i've used synchronous one......

              Regards,
              RP

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                If you need to validate after the Ajax response, put the validation code in the onreadystatecha nge anonymous function after the ready state is 4.

                Comment

                • rpnew
                  New Member
                  • Aug 2007
                  • 189

                  #9
                  Originally posted by acoder
                  If you need to validate after the Ajax response, put the validation code in the onreadystatecha nge anonymous function after the ready state is 4.
                  Hi,
                  yeah that should work.. Let me try it and i'll get back with the result....

                  Regards,
                  RP

                  Comment

                  • rpnew
                    New Member
                    • Aug 2007
                    • 189

                    #10
                    Hi,
                    Thanks for your suggestion... i've changed my validation accordingly and now its working fine with all cases...

                    Regards,
                    RP

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      Glad to hear that you got it working.

                      Comment

                      Working...