jQuery的。获得/ .POST不工作的IE 7或8,工作正常,在FF工作、正常、POST、jQuery

2023-09-11 00:36:57 作者:红提碗

我有这个基本的网页上:

 <脚本类型=文/ JavaScript的>
功能refresh_context(){
    $(#Ajax的背景下)HTML(搜索...)。
    $获得(/ AJAX / ldap_search.php,{CN:$(#用户名)VAL()},功能(XML){
        $(#Ajax的背景下)HTML($(显示,XML)的.text());
        $(#语境)VAL($(背景,XML)的.text());
    },'的xml');
}
$(文件)。就绪(函数(){
    $(#用户名),模糊(refresh_context);
});
< / SCRIPT>

<输入类型=文本名称=用户名ID =用户名最大长度=255值=/>
<输入类型=隐藏名称=上下文ID =上下文值=/>
< D​​IV ID =Ajax的背景下>< / DIV>
 

什么是应该做的(以及Firefox没有罚款)当你输入到#username领域的用户名是,它将运行/ajax/ldap_search.php?cn=$username,其搜索公​​司的LDAP的用户名并返回它的原始语境和上下文这样的格式化版本:

 <结果>
    <显示>工作人员 - &放大器; GT;会计 - &放大器; GT;约翰·史密斯< /显示器>
    <环境与GT; CN = JSMITH,OU =记帐,OU =员工,OU =用户,O = MyOrg的< /背景>
< /结果>
 

格式化版本(显示)进入到div#Ajax的背景下,去到隐藏的输入#context。 (另外, - >实际上是 - &放大器; GT;(无空格))

不过,在IE浏览器在div保持停留在搜索...并隐藏的输入值保持空白。

我都试过不用彷徨和.POST也不工作。我敢肯定,它的失败就不用彷徨,因为如果我试试这个,我甚至不得到警告:

  $得到(/ AJAX / ldap_search.php,{CN:$(#用户名)VAL()},函数(){
    警报(检查);
});
 
Jquery3.x高版本支持IE8

另外,IE浏览器并没有给我任何脚本错误。

编辑:添加$(文件)。就绪(函数(){,在.blur是在它已经在我的code,但我忘了,包括在我的文章

编辑2:请求已发送,Apache2的是接受它:

  10.135.128.96  -   -  [01 /月/ 2009:10:04:27 -0500]GET /ajax/ldap_search.php?cn=i_typed_this_in_IE HTTP / 1.1200 69
 

解决方案

问题是在ldap_search.php文件。 我有这个(根据我阅读别人的博客为例):

 标题(内容类型:应用程序/ XML,XHTML;字符集= UTF-8);
 

它实际上需要的是这对IE才能正常阅读:

 标题(内容类型:应用程序/ XML;字符集= UTF-8);
 

天哪,我讨厌IE浏览器。

I have basically this on a page:

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

What it should do (and does fine on Firefox) is when you type a username in to the #username field, it will run /ajax/ldap_search.php?cn=$username, which searches our company's ldap for the username and returns it's raw context and a formatted version of the context like this:

<result>
    <display>Staff -&gt; Accounting -&gt; John Smith</display>
    <context>cn=jsmith,ou=Accounting,ou=Staff,ou=Users,o=MyOrg</context>
</result>

The formatted version (display) goes to the div #ajax-context and goes to the hidden input #context. (Also, the -> are actually - "& g t ;" (without spaces)).

However, on IE the div stays stuck on "Searching..." and the hidden input value stays blank.

I've tried both .get and .post and neither work. I'm sure it's failing on the .get because if I try this, I don't even get the alert:

$.get("/ajax/ldap_search.php", {cn: $("#username").val()}, function() {
    alert("Check");
});

Also, IE doesn't give me any script errors.

Edit: Added "$(document).ready(function() {", the .blur was already in it in my code, but I forgot to include that in my post.

Edit 2: The request is being sent and apache2 is receiving it:

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

解决方案

Problem was in the ldap_search.php file. I had this (based on an example I read on someone's blog):

header("content-type:application/xml-xhtml;charset=utf-8");

It actually needed to be this for IE to read it properly:

header("content-type:application/xml;charset=utf-8");

God, I hate IE.