2014-06-29 77 views
0

我测试的发送和接收数据使用jQuery PHP文件和我有IE的问题(即时通讯使用IE9,但我和IE8和IE7选中)的jQuery - 获得()问题与IE7,8,9

当我点击我的div时,我向服务器发送一个“ID”,PHP文件返回答案,其工作和jQuery在其他Div和alert msg中显示结果。

当我更改接收到的php文件中的代码时,如果再次点击我的div中的一个,那么显示相同msg的jQuery即使我更改了代码,现在重播msg也不同。

当我关闭并重新打开IE时解决了这个问题。

这个问题不会发生与Firefox和铬,没有任何人有任何想法?

HTML文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> 
<head> 
    <title>test</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="X-UA-Compatible" content="IE=9" /> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    <script type="text/javascript"> 
       $(function(){ 
       $('.user').click(function(){ 
        var id_value = $(this).data('friendid'); 
        $.get('test1.php', {id: id_value}, function(data) { 
         $('#show').html(data); 
         alert(data); 
        }); 
       }) 
      }) 

    </script> 
</head> 
<body> 
<div class="user" data-friendid="1"> 
    <img src='webimgs/nopf.jpg' alt="test" /> 
    <h4>&nbsp;fullname</h4> 
    <br /> 
</div> 
<div class="user" data-friendid="2"> 
    <img src='webimgs/nopf.jpg' alt="test2"/> 
    <h4>&nbsp;fullname</h4> 
    <br /> 
</div> 
<div id="show" style="color:red"> 
</div> 
</body> 
</html> 

和PHP文件:

<?php 
if ($_GET["id"]==1) { echo "you choose number is " . $_GET["id"].", thanks." ; } 
?> 
+0

如果您已经在使用jQuery,为什么不用'$(this).data('friendid')'来代替? – Bojangles

+0

你是对的,我改变了,但这不是解决问题的任何想法? – user3780061

+0

这听起来像是一个AJAX缓存问题。尝试使用'$ .ajaxSetup({cache:false})'在进行'$ .get()'调用之前破解缓存。 – Boaz

回答

0

jQuery的。获得方法可以根据浏览器设置缓存。如果使用.post方法,它将阻止浏览器端的数据缓存。

从GET的http://www.sitepoint.com/key-differences-post/

特性引用:

  • 使用GET安全行动和POST不安全行为。
  • GET请求可以被缓存
  • GET请求可以留在浏览器历史记录
  • GET请求可以添加书签
  • GET请求可以分布&共享
  • GET请求可以被黑客攻击
1

感谢“Boaz”我使用$.ajaxSetup({cache: false})及其修复问题