0

Hi...All
I am new to Ajax in PHP
and trying the below code which works fine in Google Chrome
but not works in IExplore..
Thanks in Advance

<script language="javascript">
function showTeh(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
document.getElementById("teh").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("POST","inc/getTeh.php?q="+str,true);
xmlhttp.send();

}
</script>
2
Contributors
11
Replies
44
Views
3 Years
Discussion Span
Last Post by gsynr
0

You seem to be doing a post, but sending a get.

Line 19 and 20, try:

xmlhttp.open("POST", "inc/getTeh.php", true);
xmlhttp.send("q="+str);

unless you are in fact doing a get, in which case, change line 19 to:

xmlhttp.open("GET", "inc/getTeh.php?q="+str, true);

good luck!

Ryan

0

I also tryed with GET method
but problem is same as before

0

What is the code on the php side?
can you paste the contents of getTeh.php so we can see what the server is expecting?

If not, do you have this code available somewhere so someone can debug it?

0

d'oh!

It also may be a scoping issue.

Try this instead:

<script language="javascript">
var xmlhttp = null;  //make it global
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  };

if (xmlhttp)
{
  xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("teh").innerHTML=xmlhttp.responseText;
    }
  }
};

function showTeh(str)
{
  if (xmlhttp)
  {
    xmlhttp.abort();
    xmlhttp.open("POST","inc/getTeh.php?q="+str,true); //this still looks like a GET not a POST
    xmlhttp.send(); //because POST params are sent here
  };
}
</script>

Of course, at this point you may want to just clean up the whole instantiation of an xmlhttp object and make it a pseudo-class or a singleton of sorts, but that's for another lesson :-P

See if the above helps.

Ryan

0

I also tried by making xmlhttp as global as given in below code
but result is same i.e. not works in iexplorer

<script language="javascript">
var xmlhttp=null;
function showTeh(str)
{
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
document.getElementById("teh").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","inc/getTeh.php?q="+str,true);
xmlhttp.send();

}
</script>
0

code of getTeh.php file is as given below

$s=$_GET["q"];
$teh=mysql_query("SELECT district.tId, district.tName FROM district WHERE district.dId = '$s' order by district.tId") or die("Query");
while ($row=mysql_fetch_array($teh)){
extract($row);
echo "<option value='$tId'>$tName</option>";
}}
0

Live example can be seen at
Www.cpsharyana.com/register.php

0

Kindly check IE6.0 IE9.0
Its not working at all
On Selection of District(Yamunanagar), Tehsil/Block not loads in any version of IExplorer...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.