467,077 Members | 1,022 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

xmlhttpobj.open() issue in FIREFOX

omerbutt
512MB
sir i am making an inventory application with the help of ajax,html,dhtml,javascript php and mysql i have been working with AJAX and ASP CLASSIC ,but now i have switched to php the problem i am facing is that i have made a form and now i want to post this form through AJAX funtion named Addstk(frmobj); on to a next php page where i am getting the form input values ,i have declared the getxmlhttpobject() function and the statechanged() function too i am using the post method where i am sending the concatenated string through send(str) to ad_stk_done.php but it gives me error at the line where i try to open that file with the xmlhttpobject in the JS file ,but this only happens in the case of FIREFOX where as in internet explorer it is running accurately, i have listed code here any suggestions would be highly appreciated,
regards,
omer
the error code is here

Expand|Select|Wrap|Line Numbers
  1. Error: xmlHttp.Open is not a function
  2. Source File: http://localhost/ashar/js/Ad_stk2.js
  3. Line: 80
  4.  
the getxmlhttp funtion is here

Expand|Select|Wrap|Line Numbers
  1. function GetXmlHttpObject()
  2. {
  3.     xmlHttp=null;
  4.     try
  5.       {
  6.       // Firefox, Opera 8.0+, Safari
  7.       xmlHttp=new XMLHttpRequest();
  8.       }
  9.     catch (e)
  10.       {
  11.       // Internet Explorer
  12.       try
  13.         {
  14.         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  15.         }
  16.       catch (e)
  17.         {
  18.             xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  19.         }
  20.       }
  21.  
  22.     return xmlHttp;
  23. }
  24.  
the state changed funtion is here

Expand|Select|Wrap|Line Numbers
  1. function StateChanged()
  2. {
  3.     if(xmlHttp.readystate==4)    
  4.     {
  5.         if (xmlHttp.status==200) 
  6.         {
  7.                document.getElementById('code_no').value = xmlHttp.responseText;
  8.                document.getElementById('code_no').focus();
  9.         }
  10.         else
  11.         {
  12.             alert("ERROR Occurred");
  13.             return false;
  14.         }
  15.  
  16.     }
  17. }
  18.  
the funtion to add value to databse through AJAX when the submit button is clicked is here

Expand|Select|Wrap|Line Numbers
  1. function Addstk(fobj)
  2. {    
  3.     var str;
  4.     str="";
  5.     var vl;    
  6.     vl=ValidateInputs(fobj);
  7.     if(vl=="")
  8.     {
  9.         var qtty;
  10.         var st1; 
  11.         var st2;
  12.         var st3; 
  13.         var sroom;
  14.         str=Getformvalues(fobj,"validate");
  15.  
  16.         qtty=eval(document.getElementById('qtty').value);
  17.         sroom=eval(document.getElementById('show_room').value);
  18.         st1=eval(document.getElementById('store_1').value);
  19.         st2=eval(document.getElementById('store_2').value);
  20.         st3=eval(document.getElementById('store_3').value);
  21.         sroom=sroom+st2+st3+st1;
  22.  
  23.         if(qtty==sroom)
  24.         {
  25.             xmlHttp=GetXmlHttpObject();
  26.             alert(xmlHttp);
  27.             if(xmlHttp==null)
  28.             {
  29.                 alert("your browser version is not supported");
  30.                 return false;
  31.             }
  32.             if(document.getElementById('resinp').value!=0)
  33.             {
  34.                 removeResdiv();
  35.             }
  36.             alert("about to open");
  37.             xmlHttp.onreadystatechange=StateChanged;
  38.             xmlHttp.Open("POST","ad_stk_done.php",true);
  39.             xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
  40.             xmlHttp.send(str);
  41.         }
  42.         else
  43.         {
  44.             alert("the quantity entered is not equal");
  45.             return false;
  46.         }
  47.  
  48.     }
  49.     else 
  50.     {
  51.         alert(vl);
  52.         return false;
  53.     }
  54. }
  55.  
the string concatenation funtion Getformvalues(fobj,valFunc) is here

Expand|Select|Wrap|Line Numbers
  1. function Getformvalues(fobj,valFunc)
  2. {
  3.     var str;
  4.     str="";
  5.     var cmd;
  6.     cmd="";
  7.     var val;
  8.     val="";
  9.  
  10.     for(var i=0;i<fobj.elements.length;i++)
  11.         {
  12.             switch(fobj.elements[i].type)
  13.             {
  14.                 case "text":
  15.                 if(valFunc)
  16.                 {
  17.                     cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
  18.                     val = eval('cmd');
  19.                 }
  20.                 str += fobj.elements[i].name + "=" + fobj.elements[i].value + "&";
  21.                 break;
  22.  
  23.                 case "select-one":
  24.                 str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
  25.                 break;
  26.             }
  27.         }
  28.     str = str.substr(0,(str.length - 1));
  29.     return str;
  30. }
  31.  
Feb 12 '08 #1
  • viewed: 2304
Share:
3 Replies
acoder
Expert Mod 8TB
JavaScript is case-sensitive. Open() should obviously be open().
Feb 12 '08 #2
omerbutt
512MB
JavaScript is case-sensitive. Open() should obviously be open().
sir i have done as u said but now it gets into the statechanged() funtion but does not get into the check of readystate==4 and xmlobj.status==200
the code is here
Expand|Select|Wrap|Line Numbers
  1. function StateChanged()
  2. {
  3.     alert("into statechanged");
  4.     if(xmlHttp.readystate==4)    
  5.     {
  6.         if (xmlHttp.status==200) 
  7.         {
  8.              alert("status 200");
  9.  
  10.           var a;
  11.           a=xmlHttp.responseText;
  12.            alert(a);
  13.            document.getElementById('code_no').focus();
  14.         }
  15.         else
  16.         {
  17.             alert("ERROR Occurred");
  18.             return false;
  19.         }
  20.  
  21.     }
  22. }
  23.  
the code for the php file ad_stk_done.php where i am getting the values is here
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $codeno=$_POST["code_no"];
  3. $prtno=$_POST["prt_no"];
  4. $prd=$_POST["prd"];
  5. $brand=$_POST["brand"];
  6. $auto=$_POST["auto"];
  7. $uprc=$_POST["unit_price"];
  8. $qtty=$_POST["qtty"];
  9. $sroom=$_POST["show_room"];
  10. $st1=$_POST["store_1"];
  11. $st2=$_POST["store_2"];
  12. $st3=$_POST["store_3"];
  13. $size=$_POST["size"];
  14. $height=$_POST["height"];
  15. $od1=$_POST["out_d1"];
  16. $od2=$_POST["out_d2"];
  17. $id1=$_POST["in_d1"];
  18. $id2=$_POST["in_d2"];
  19. $trep=$_POST["t_rep"];
  20. $rp1=$_POST["rp_no1"];
  21. $rp2=$_POST["rp_no2"];
  22. $rp3=$_POST["rp_no3"];
  23. $rp4=$_POST["rp_no4"];
  24. $rp5=$_POST["rp_no5"];
  25. $rp6=$_POST["rp_no6"];
  26. echo $codeno;
  27. ?>
  28.  
Feb 12 '08 #3
acoder
Expert Mod 8TB
Another 'case-sensitivitus': readystate should be readyState.
Feb 12 '08 #4

Post your reply

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

Similar topics

8 posts views Thread by Dominic Tocci | last post: by
18 posts views Thread by len.hartley@gmail.com | last post: by
3 posts views Thread by SAL | last post: by
1 post views Thread by bruce | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.