0

可能重复:
脚本在 Ajax 中不起作用返回值

我正在使用 ajax 来获取一些数据。有一个链接“显示此用户的项目”。当点击它时,它将调用一个带有参数 'userid' 的函数 'callfunc'。这个 ajax 函数将转到 getdetails.php 和将获取该相应用户的一些详细信息。

<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();
}

获取详细信息.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>';
}
?>

此代码在 mozilla、chrome 和 opera 中正常工作。但在 IE 中无法正常工作。单击“显示此用户的项目”链接时,IE 中没有任何反应。知道吗?

4

2 回答 2

0

看看Jquery ajax()。它支持几乎所有浏览器。请注意,Jquery 的下一个版本 1.9 版将放弃对 ie9 之前的所有 IE 浏览器的支持。

$.ajax({
  type: "GET",
  url: "getdetails.php",
  data: { cid : str }
}).done(function(response) {
  $('#result').text() = response;
});
于 2013-01-04T05:10:47.163 回答
-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>

至少试试这段代码,它会在浏览器中为您提供状态或任何错误....

于 2013-01-04T05:47:21.143 回答