kamkam
10-21-2007, 06:40 AM
Hi;
I am try to use the xmlHttp.responseText's value, but i find it some time works, some time does not work.
in my code, i got some buttons as < 1 2 3 >.
after i click the above buttons, some times it pop up a window
with undifine, some times it pop up a window with the right value. This is my code's problem, could any one help me to solve this problem, please.
index.html
<html>
<body>
<input type="button" id="b<" name="bb<" value="<" onClick="cButtons()">
<input type="button" id="b1" name="bb1" value="1" onClick="cButtons()">
<input type="button" id="b2" name="bb2" value="2" onClick="cButtons()">
<input type="button" id="b3" name="bb3" value="3" onClick="cButtons()">
<input type="button" id="b>" name="bb>" value=">" onClick="cButtons()">
<script type="text/javascript">
var rValue;
function cButtons(){
ajaxFunction();
alert(rValue);
}
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
rValue=xmlHttp.responseText;
}
}
xmlHttp.open("GET","cateV.php",true);
xmlHttp.send(null);
}
</script>
</body>
</html>
cateV.php
<?php
$test="i am testing";
echo $test;
?>
I am try to use the xmlHttp.responseText's value, but i find it some time works, some time does not work.
in my code, i got some buttons as < 1 2 3 >.
after i click the above buttons, some times it pop up a window
with undifine, some times it pop up a window with the right value. This is my code's problem, could any one help me to solve this problem, please.
index.html
<html>
<body>
<input type="button" id="b<" name="bb<" value="<" onClick="cButtons()">
<input type="button" id="b1" name="bb1" value="1" onClick="cButtons()">
<input type="button" id="b2" name="bb2" value="2" onClick="cButtons()">
<input type="button" id="b3" name="bb3" value="3" onClick="cButtons()">
<input type="button" id="b>" name="bb>" value=">" onClick="cButtons()">
<script type="text/javascript">
var rValue;
function cButtons(){
ajaxFunction();
alert(rValue);
}
function ajaxFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
rValue=xmlHttp.responseText;
}
}
xmlHttp.open("GET","cateV.php",true);
xmlHttp.send(null);
}
</script>
</body>
</html>
cateV.php
<?php
$test="i am testing";
echo $test;
?>