0

Possible Duplicate:
script not working in Ajax returned value

I am using ajax for fetching some data.There is a link "Show items of this user".while cliking on it it will call a function 'callfunc' with parameter 'userid'.This ajax function will go to getdetails.php and and will fetch some details of that corresponding user.

<tr><td colspan="6" align="right"><a href="javascript:callfunc(<?= $row5[user_id]; ?>)" style="font-size:10px;">Show items of this user</a></td></tr>


<script type="text/javascript">
function callfunc(str)
{

//alert(str);
if (str.length==0)
{ 
document.getElementById("result").innerHTML="";
return;
}
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("result").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getdetails.php?cid="+str,true);
xmlhttp.send();
}

getdetails.php

<?php
require 'include/connect.php';
$cid=$_GET['cid'];
$sql="select * from table where status='Active' and user_id=$cid";
$res=mysql_query($sql); 
$tot=mysql_num_rows($res);
if($tot>0){
while($row=mysql_fetch_array($res))
{
echo '<tr class="detail9txt" height="30"> 
      <td width="2%"><input type="checkbox" name="item" id="item" value="'.$row[item_id].'"></td>
      <td align="center" width="12%" style="vertical-align:baseline;">
        <a href="detail.php?item_id='.$row[item_id].'" id="link3">'.$row['title'].'</a>
      </td> 
<td align="center" width="17%" style="vertical-align:baseline;">
'.substr($row['des'], 0, 20).'
</td></tr>';
}
?>

This code is working properly in mozilla,chrome,and opera.But not working in IE.While clicking on the link "Show Items of this user" nothing happens in IE.Any idea?

Community
  • 1
  • 1
asitha
  • 219
  • 1
  • 4
  • 17
  • 1
    You should start using a javascript library like **jQuery** – Dr. Dan Jan 04 '13 at 05:09
  • 2
    [**Please, don't use `mysql_*` functions in new code**](http://stackoverflow.com/a/14110189/1723893). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – NullPoiиteя Jan 04 '13 at 05:10
  • 3
    Are you a bot @NullPointer? Every time someone uses ext:mysql you are copy-pasta... – Mr. Polywhirl Jan 04 '13 at 05:12
  • Microsoft failed to properly implement XMLHttpRequest in IE7. `XHR` can't require local files properly. You should use `ActiveX` object in `IE` even if `XHR` is available – Yang Jan 04 '13 at 05:13
  • The exact same ajax code works fine here: http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first . Maybe an issue with your html? You are not showing what "result" looks like. – Christophe Jan 04 '13 at 06:35
  • @Mr.Polywhirl: https://gist.github.com/3881905 More details on the [**PHP Chat**](http://chat.stackoverflow.com/rooms/11/php) – Madara's Ghost Jan 04 '13 at 12:31

2 Answers2

0

Take a look at Jquery ajax(). It supports just about every browser. Please be mindful that the next release of Jquery, version 1.9, will be dropping support for all IE browsers before ie9.

$.ajax({
  type: "GET",
  url: "getdetails.php",
  data: { cid : str }
}).done(function(response) {
  $('#result').text() = response;
});
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
Mr. Polywhirl
  • 42,981
  • 12
  • 84
  • 132
  • 1
    Not an answer. Can be a comment! And dont know who is give up vote to such answers! – madhairsilence Jan 04 '13 at 05:16
  • Please don't get butthurt. – Mr. Polywhirl Jan 04 '13 at 05:39
  • I tried But nothing happens while clicking on the link "show items of this member" – asitha Jan 04 '13 at 05:53
  • Ensure that you have the following script reference in your document head and that it comes before all other libraries: `` – Mr. Polywhirl Jan 04 '13 at 06:04
  • Not helpful to explain the issue. And jQuery 1.9 will support IE 6/7/8 (cf. the link in your reply). – Christophe Jan 04 '13 at 06:20
-1
  <script type="text/javascript">
    function callfunc(str)
    {
    try{
    var ox = ((window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
            if (ox) {
                ox.open("GET", "getdetails.php?cid="+str);
                ox.setRequestHeader("Content-Type", "text/html");
                ox.setRequestHeader("Connection", "close");
                ox.onreadystatechange = function () {
                    if (ox.readyState == 4) {
                        if (ox.status == 200) {
                            eval(callback_function + "('" + escape(ox.responseText) + "')");
                        } else {
                           alert(ox.readyState);
                           alert(ox.stauts);
                        }
                    }
                }
                ox.send(null);
            }
    }catch(e){
    alert(e.Message);
    }

    }

</script>

Try this code atleast it will provide you status or any error in ie browser....

THE ONLY ONE
  • 2,110
  • 1
  • 12
  • 6