xmlhttpobj.open() issue in FIREFOX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #1

    xmlhttpobj.open() issue in FIREFOX

    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 getxmlhttpobjec t() 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

    Code:
    Error: xmlHttp.Open is not a function
    Source File: http://localhost/ashar/js/Ad_stk2.js
    Line: 80
    the getxmlhttp funtion is here

    Code:
    function GetXmlHttpObject()
    {
    	xmlHttp=null;
    	try
    	  {
    	  // Firefox, Opera 8.0+, Safari
    	  xmlHttp=new XMLHttpRequest();
    	  }
    	catch (e)
    	  {
    	  // Internet Explorer
    	  try
    		{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
    	  catch (e)
    		{
    			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    	  }
    	  
    	return xmlHttp;
    }
    the state changed funtion is here

    Code:
    function StateChanged()
    {
    	if(xmlHttp.readystate==4)	
    	{
    		if (xmlHttp.status==200) 
    		{
      	         document.getElementById('code_no').value = xmlHttp.responseText;
    	           document.getElementById('code_no').focus();
    		}
    		else
    		{
    			alert("ERROR Occurred");
    			return false;
    		}
    
    	}
    }
    the funtion to add value to databse through AJAX when the submit button is clicked is here

    Code:
    function Addstk(fobj)
    {	
    	var str;
    	str="";
    	var vl;	
    	vl=ValidateInputs(fobj);
    	if(vl=="")
    	{
    		var qtty;
    		var st1; 
    		var st2;
    		var st3; 
    		var sroom;
    		str=Getformvalues(fobj,"validate");
    
    		qtty=eval(document.getElementById('qtty').value);
    		sroom=eval(document.getElementById('show_room').value);
    		st1=eval(document.getElementById('store_1').value);
    		st2=eval(document.getElementById('store_2').value);
    		st3=eval(document.getElementById('store_3').value);
    		sroom=sroom+st2+st3+st1;
    
    		if(qtty==sroom)
    		{
    			xmlHttp=GetXmlHttpObject();
    			alert(xmlHttp);
    			if(xmlHttp==null)
    			{
    				alert("your browser version is not supported");
    				return false;
    			}
    			if(document.getElementById('resinp').value!=0)
    			{
    				removeResdiv();
    			}
    			alert("about to open");
    			xmlHttp.onreadystatechange=StateChanged;
    			xmlHttp.Open("POST","ad_stk_done.php",true);
    			xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
    			xmlHttp.send(str);
    		}
    		else
    		{
    			alert("the quantity entered is not equal");
    			return false;
    		}
    		
    	}
    	else 
    	{
    		alert(vl);
    		return false;
    	}
    }
    the string concatenation funtion Getformvalues(f obj,valFunc) is here

    Code:
    function Getformvalues(fobj,valFunc)
    {
    	var str;
    	str="";
    	var cmd;
    	cmd="";
    	var val;
    	val="";
    
    	for(var i=0;i<fobj.elements.length;i++)
    		{
    			switch(fobj.elements[i].type)
    			{
    				case "text":
    				if(valFunc)
    				{
    					cmd = valFunc + "(" + 'fobj.elements[i].value' + ")";
    					val = eval('cmd');
    				}
    				str += fobj.elements[i].name + "=" + fobj.elements[i].value + "&";
    				break;
    				
    				case "select-one":
    				str += fobj.elements[i].name + "=" + fobj.elements[i].options[fobj.elements[i].selectedIndex].value + "&";
    				break;
    			}
    		}
    	str = str.substr(0,(str.length - 1));
    	return str;
    }
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    JavaScript is case-sensitive. Open() should obviously be open().

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      Originally posted by acoder
      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
      Code:
      function StateChanged()
      {
      	alert("into statechanged");
      	if(xmlHttp.readystate==4)	
      	{
      		if (xmlHttp.status==200) 
      		{
      			 alert("status 200");
      			 
      		  var a;
      		  a=xmlHttp.responseText;
      	 	  alert(a);
       		  document.getElementById('code_no').focus();
      		}
      		else
      		{
      			alert("ERROR Occurred");
      			return false;
      		}
      
      	}
      }
      the code for the php file ad_stk_done.php where i am getting the values is here
      Code:
      <?
      $codeno=$_POST["code_no"];
      $prtno=$_POST["prt_no"];
      $prd=$_POST["prd"];
      $brand=$_POST["brand"];
      $auto=$_POST["auto"];
      $uprc=$_POST["unit_price"];
      $qtty=$_POST["qtty"];
      $sroom=$_POST["show_room"];
      $st1=$_POST["store_1"];
      $st2=$_POST["store_2"];
      $st3=$_POST["store_3"];
      $size=$_POST["size"];
      $height=$_POST["height"];
      $od1=$_POST["out_d1"];
      $od2=$_POST["out_d2"];
      $id1=$_POST["in_d1"];
      $id2=$_POST["in_d2"];
      $trep=$_POST["t_rep"];
      $rp1=$_POST["rp_no1"];
      $rp2=$_POST["rp_no2"];
      $rp3=$_POST["rp_no3"];
      $rp4=$_POST["rp_no4"];
      $rp5=$_POST["rp_no5"];
      $rp6=$_POST["rp_no6"];
      echo $codeno;
      ?>

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Another 'case-sensitivitus': readystate should be readyState.

        Comment

        Working...