[英]ie and jquery $.get not working
我正在尝试使用$.get
调用更新div的内容,但是在ie(9).
失败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或其他版本)
有什么线索吗?
快速更新
似乎是在缓存中保存了先前$ .get调用中的某些数据。 基本上,我在屏幕上有一个div,当用户单击一个按钮时,将打开一个带有textarea的图层,该文本可通过nicedit进行编辑。 在textarea中填充$ .get,然后用户单击“保存”,隐藏图层,并使用相同的$ .get调用更新父页面上的原始div。
在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调用有关
这不是一个答案,因为问题不完整,但是我需要发布代码注释来帮助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)如果其他所有方法均失败,请查看此普通JS是否可在IE中运行,以验证它不是jQuery选择器问题。
var elem = document.getElementById(box_id);
alert(elem);
elem.innerHTML = data;
我解决了这个问题。 与选择器无关,但与参数变量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
的局部变量
好的问题解决了,我知道这很明显。
在原始$ .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});
});
});
}
感谢所有的投入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.