AJAX功能在IE7和IE8中不起作用

时间:2013-07-19 05:14:25

标签: php jquery html ajax

我遇到的问题是我的AJAX功能在Chrome,Firefox和IE 9中运行良好,但在IE 7和IE 8中无效。

这是我的AJAX代码。

var url = 'abcd.php';
var dataString = '&id='+id+'&type=mesg';
$.ajax({
    url: url,
    global: true,
    type: "POST",
    data: dataString,
    dataType: "html",
    success: function(msg)
       {
       alert(msg);
           $('#main_data').html(msg);
       }
    });

它在alert msg之前正常工作,但不显示任何输出。

请帮帮我。

3 个答案:

答案 0 :(得分:1)

我认为您使用的jquery version 2+不支持< IE 9

不再支持IE 6/7/8: Remember that this can also affect IE9 and even IE10 if they are used in their “Compatibility View” modes that emulate older versions. To prevent these newer IE versions from slipping back into prehistoric modes, we suggest you always use an X-UA-Compatible tag or HTTP header. If you can use the HTTP header it is slightly better for performance because it avoids a potential browser parser restart.

阅读jquery-2-0-released

所以,你应该使用jquery version 1.9 for older versions of IE like IE 6,7,8 或者您可以将其添加到html page

<!--[if lt IE 9]>
<script src="jquery-1.9.0.js"></script>
<![endif]-->
<!--[if gte IE 9]>
<script src="jquery-2.0.0.js"><</script>
<![endif]-->

答案 1 :(得分:0)

使用此代码

$.support.cors= true;
var url = 'abcd.php';
var dataString = '&id='+id+'&type=mesg';
$.ajax({
async: false,
url: url,
global: true,
type: "POST",
data: dataString,
dataType: "html",
success: function(msg)
   {
   alert(msg);
       $('#main_data').html(msg);
   }
});

答案 2 :(得分:0)

如果您使用UTF-8对AJAX响应进行编码,IE无法自动确定,除此之外会引发异常:“系统错误1072896658”。

AJAX but in IE

另请参阅详细信息:http://keelypavan.blogspot.com/2006/07/system-error-1072896658-in-ie.html

然后是一个解决方案。您应该在abcd.php中添加HTTP标头以声明编码。

e.g。

<?php

//... do something
header('Content-Type: text/html; charset=utf-8');
echo $resonse_text;