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>

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

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

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?

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

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>

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>";
}}

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

I see you got it working :)

Good luck :-D

No ,
Its not working on Internet Explorer

I tried it in IE, and the select list updated... what did you expect to happen?

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.