2013-01-04 50 views
0

可能重复:
script not working in Ajax returned valueAjax代码在IE.But罚款不工作中的所有其他浏览器

我使用AJAX用于获取一些data.There是一个链接“查看项目这个用户“。同时登录它会调用一个带有参数'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(); 
} 

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>'; 
} 
?> 

此代码是在Mozilla,Chrome的正常工作,并在opera.But不IE.While工作单击“该用户的显示项目”的链接没有任何反应在IE.Any的想法?

+1

你应该开始使用JavaScript库,例如jQuery的** ** –

+2

[**请,请不要在新代码中使用'mysql_ *'函数**](http://stackoverflow.com/a/14110189/1723893)。他们不再被维护[并被正式弃用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**红框**](http://j.mp/Te9zIL)?学习[*准备的语句*](http://j.mp/T9hLWi),并使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [这篇文章](http://j.mp/QEx8IB)将帮助你决定哪个。如果你选择PDO,[这里是一个很好的教程](http://j.mp/PoWehJ)。 –

+3

你是一个bot @NullPointer吗?每次有人使用ext:mysql时,您都是复制意大利面... –

回答

0

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

$.ajax({ 
    type: "GET", 
    url: "getdetails.php", 
    data: { cid : str } 
}).done(function(response) { 
    $('#result').text() = response; 
}); 
+1

不是答案。可以是评论!而不知道谁会放弃投票给这样的答案! – madhairsilence

+0

请不要吝啬。 –

+0

我试图<脚本类型= “文本/ JavaScript的”> 功能callfunc(STR) { $就({ 类型: “GET”, URL: “getdetails.php”, 数据:{CID: (函数(响应){('#result').text()=响应; }); }但点击链接“显示此会员的项目” – asitha

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

试试这个代码ATLEAST它会为您提供状态或在IE浏览器的任何错误....

+0

没有任何反应,也没有任何警报 – asitha

相关问题