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
the getxmlhttp funtion is here
the state changed funtion is here
the funtion to add value to databse through AJAX when the submit button is clicked is here
the string concatenation funtion Getformvalues(f obj,valFunc) is here
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
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;
}
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;
}
}
}
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;
}
}
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;
}
Comment