By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

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

rpnew
100+
P: 188
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
Jan 29 '08 #1
Share this Question
Share on Google+
10 Replies


acoder
Expert Mod 15k+
P: 16,027
Either post the code or a link to a test page.
Jan 29 '08 #2

rpnew
100+
P: 188
Either post the code or a link to a test page.
Hi,
Here is the Ajax code..
Expand|Select|Wrap|Line Numbers
  1. <!-- Function for HTTPRequest object-->
  2. function getHTTPObject() 
  3.     var xmlhttp; 
  4.     if (window.ActiveXObject) 
  5.     {
  6.         try 
  7.         {
  8.             xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  9.         }
  10.         catch (e)
  11.         {
  12.             try
  13.             {
  14.                 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  15.             }
  16.             catch (E) 
  17.             {
  18.                 xmlhttp = false;
  19.             }
  20.         }
  21.     } 
  22.     else
  23.     {
  24.         xmlhttp = false;
  25.     }
  26.     if (window.XMLHttpRequest) 
  27.     {
  28.         try
  29.         {
  30.             xmlhttp = new XMLHttpRequest();
  31.         } 
  32.         catch (e) 
  33.         {
  34.             xmlhttp = false;
  35.         }
  36.     } 
  37.     return xmlhttp; 
  38. }
  39.  
  40. <!-- Function for checking duplicate names....-->
  41.     function validatenames()
  42.     {
  43.         var htpobj = getHTTPObject();    
  44.         var str = document.mod_form.Mod_Name.value;
  45.         var pname=document.mod_form.Prod_Name.value
  46.         url='checknames.php?mname='+str+'&pname='+pname;
  47.         htpobj.open("GET", url, false);
  48.         htpobj.onreadystatechange = function()
  49.                         {
  50.                             if (htpobj.readyState == 4) 
  51.                             {
  52.                                 if(htpobj.responseText == 1)
  53.                                 {
  54.                                     alert(htpobj.responseText);
  55.                                     document.getElementById('vlnames').value=0;
  56.                                     document.mod_form.Mod_Name.focus();
  57.  
  58.                                 }
  59.                                 else
  60.                                 {
  61.                                     document.getElementById('vlnames').value=1;
  62.                                     alert(htpobj.responseText);
  63.                                     document.mod_form.Mod_Desc.focus();
  64.                                 }
  65.                             }
  66.                         }
  67.         htpobj.send(null);
  68.     }
  69.  
Here is where i'm calling it....
Expand|Select|Wrap|Line Numbers
  1. <!-- Function for checking blank fields....-->
  2.     function validate_form()
  3.     {
  4.         validatenames();
  5.         //document.write(document.feat_tab.width);
  6.         tr=true;
  7.         if(document.mod_form.Prod_Name.value == "")
  8.         {
  9.             tr = false;
  10.             alert('Product Id blank');
  11.             return tr;
  12.         }
  13.         else if(document.mod_form.Mod_Name.value == "")
  14.         {
  15.             tr = false;
  16.             alert('Module Name Field Can\'t Be Blank');
  17.             return tr;
  18.         }
  19.         else if(document.mod_form.vlnames.value==0)
  20.         {
  21.             tr=false;
  22.             alert('Duplicate Module Name Is Not Allowed');
  23.             document.mod_form.Mod_Name.focus();
  24.             return tr;
  25.         }
  26.         else
  27.         {
  28.             var agre=confirm('are you sure you want to submit the data???') ;
  29.             if(!agre) return false;
  30.             else 
  31.             {
  32.                 //refresh_feat_frame();
  33.                 return true;
  34.             }
  35.         }
  36.  
  37.     }
  38.  
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
Jan 30 '08 #3

acoder
Expert Mod 15k+
P: 16,027
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.
Jan 30 '08 #4

rpnew
100+
P: 188
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 Onreadystatechange???

Regards,
RP
Jan 30 '08 #5

acoder
Expert Mod 15k+
P: 16,027
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?
Jan 30 '08 #6

rpnew
100+
P: 188
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
Jan 30 '08 #7

acoder
Expert Mod 15k+
P: 16,027
If you need to validate after the Ajax response, put the validation code in the onreadystatechange anonymous function after the ready state is 4.
Jan 30 '08 #8

rpnew
100+
P: 188
If you need to validate after the Ajax response, put the validation code in the onreadystatechange 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
Jan 30 '08 #9

rpnew
100+
P: 188
Hi,
Thanks for your suggestion... i've changed my validation accordingly and now its working fine with all cases...

Regards,
RP
Jan 31 '08 #10

acoder
Expert Mod 15k+
P: 16,027
Glad to hear that you got it working.
Jan 31 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.