我基本上在页面上有这个:
<script type="text/javascript">
function refresh_context() {
$("#ajax-context").html("Searching...");
$.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function(xml) {
$("#ajax-context").html($("display", xml).text());
$("#context").val($("context", xml).text());
}, 'xml');
}
$(document).ready(function() {
$("#username").blur(refresh_context);
});
</script>
<input type="text" name="username" id="username" maxlength="255" value="" />
<input type="hidden" name="context" id="context" value=""/>
<div id="ajax-context"></div>
它应该做的(并且在 Firefox 上做的很好)是当你在#username 字段中输入用户名时,它将运行/ajax/ldap_search.php?cn=$username,它会在我们公司的 ldap 中搜索用户名并返回它的原始上下文和上下文的格式化版本,如下所示:
<result>
<display>Staff -> Accounting -> John Smith</display>
<context>cn=jsmith,ou=Accounting,ou=Staff,ou=Users,o=MyOrg</context>
</result>
格式化版本(显示)转到div #ajax-context 并转到隐藏输入#context。 (此外,-> 实际上是 - "& g t ;"(没有空格))。
但是,在 IE 上,div 停留在“搜索中...”并且隐藏的输入值保持空白。
我已经尝试了 .get 和 .post,但都不起作用。我确定它在 .get 上失败了,因为如果我尝试这样做,我什至不会收到警报:
$.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function() {
alert("Check");
});
此外,IE 不会给我任何脚本错误。
编辑:添加了“$(document).ready(function() {”,.blur 已经在我的代码中了,但我忘了在我的帖子中包含它。
编辑 2:正在发送请求,apache2 正在接收它:
10.135.128.96 - - [01/May/2009:10:04:27 -0500] "GET /ajax/ldap_search.php?cn=i_typed_this_in_IE HTTP/1.1" 200 69
最佳答案
问题出在 ldap_search.php 文件中。 我有这个(基于我在某人博客上阅读的示例):
header("content-type:application/xml-xhtml;charset=utf-8");
为了让 IE 正确阅读它实际上需要这样:
header("content-type:application/xml;charset=utf-8");
上帝,我讨厌 IE。
关于javascript - jquery .get/.post 在 ie 7 或 8 上不工作,在 ff 中工作正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/811672/