0

我正在尝试通过$.get调用更新 div 的内容,但它失败了ie(9).

js是这个

function UpdateElementOfParent(box_id, page_ref, template_ref)
{
 $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
  .done(function(data) {                  
         $('#'+box_id).html(data);              
      });  
}

get_content.php

  <?php   
include("connect.php"); 
$page_ref = $_GET['page_ref'];  
$template_ref = $_GET['template_ref'];
$box_id = $_GET['box_id'];  
$sql = mysql_query("SELECT * FROM site_content WHERE page_ref='$page_ref' AND template_ref='$template_ref' AND box_id='$box_id' AND box_type='text'");
while($row=mysql_fetch_array($sql))  
    {  
      echo stripslashes($row['content']);  
    }  
   ?> 

它工作正常firefox/chrome/safari and opera.

php更新了数据库但div ("#"+box_id)没有更新ie(只有ie9手头所以不知道它是否只有9或其他版本)

任何线索?

快速更新

似乎 ie 正在缓存中保存来自先前 $.get 调用的一些数据。基本上我在屏幕上有一个 div,当用户单击一个按钮时,会打开一个带有可使用 nicedit 编辑的 textarea 的图层。textarea 填充了 $.get,然后用户单击保存,图层被隐藏,并且父页面上的原始 div 使用相同的 $.get 调用进行更新。

在ie中,如果我更改内容,db会更新但div不会更新,当我打开图层时,它仍然显示旧数据。

第一个 $.get 电话是这样的

$.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
  .done(function(data) {         
      document.getElementById("edit_content").value=data; 
      area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});              
      });  

警报数据不会在 IE 中显示更新的文本,因此它肯定与 $.get 调用有关

4

3 回答 3

0

好的问题解决了,我知道这是非常明显的事情。

在原始 $.get 函数调用中,我必须设置 document.ready 状态

function get_edit_content(box_id,page_ref,template_ref)
  {
    $(document).ready(function() { <<<<<HERE   
        if(area1) {     
           area1.removeInstance('edit_content');
           area1 = null;
           document.getElementById("edit_content").value="";         
         }
        $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref } )
        .done(function(data) {       
           document.getElementById("edit_content").value=data;         
           document.getElementById("page_ref").value=page_ref;
           document.getElementById("template_ref").value=template_ref;          
           document.getElementById("box_id").value = box_id;                     
           area1 = new nicEditor({fullPanel : true}).panelInstance("edit_content",{hasPanel : true});             
         });  
    });

}

感谢所有的投入

于 2013-04-16T09:18:38.380 回答
0

这不是答案,因为问题不完整,但我需要发布代码评论以协助 OP。

正如您提到的 PHP 工作得很好,问题可能是 IE 不喜欢 jQuery 中的动态选择器。请尝试以下几个选项:

1)$('#'+box_id).html(data);改为:

var id = '#'+box_id;
$(id).html(data);

2) 尝试记录或警告元素,看看 IE 是否真的得到了正确的元素:

var elem = $('#'+box_id);
alert(elem);
elem.html(data);

[HTMLDivElement]如果元素存在,这将显示为或类似的东西。

3) 如果一切都失败了,看看这个 vanilla JS 是否在 IE 中工作,以验证它不是 jQuery 选择器问题。

var elem = document.getElementById(box_id);
alert(elem);
elem.innerHTML = data;
于 2013-04-16T08:23:45.147 回答
0

我解决了这个问题。与选择器无关,而与参数变量的范围有关box_id

将您的功能更改为:

function UpdateElementOfParent(box_id, page_ref, template_ref) {

    myBox = box_id;
    $.get("get_content.php", { box_id: box_id, page_ref: page_ref, template_ref:template_ref })
        .done(function(data) {                  
             $('#'+myBox).html(data);              
        });  
}

解释:

AJAX 回调函数无权访问本地变量UpdateElementOfParent

于 2013-04-16T08:26:49.550 回答