jQuery.ajax() - 在IE9返回不确定的数据不确定、数据、jQuery、ajax

2023-09-10 17:14:59 作者:生死皆闲事

我有一个非常简单的code:

  $。阿贾克斯({
  缓存:假的,
  数据类型:HTML,
  完成:功能(jqXHR){
    执行console.log(jqXHR.responseText);
  },
  成功:功能(数据){
    的console.log(数据);
  },
  网址:http://follows.pl/pages/ajaxtest
});
 

返回在FF,Chrome和IE8的一些文字,但在IE9它显示了两次不确定。

我已经研究过的开发工具在IE9中,它呈现出正常的响应所以请求工作正常,反应是好的,但变量是不确定的。

响应报头:

 响应HTTP / 1.1 200 OK
缓存控制无缓存
内容类型text / html;字符集:UTF-8
语用无缓存
 

响应

 串(4)测试
 
AJAX笔记

解决方案

我怀疑这是你的问题:

 内容类型text / html;字符集:UTF-8
 

该值的格式不正确(在':'之后的字符集是错误的)和IE9不喜欢,只是默默地失败而不是说一些有用的东西。试试这个:

 的Content-Type:text / html的;字符集= UTF-8
 

i have a very simple code:

$.ajax({
  cache: false,
  dataType: 'html',
  complete: function(jqXHR){
    console.log(jqXHR.responseText);
  },
  success: function(data){
    console.log(data);
  },
  url: 'http://follows.pl/pages/ajaxtest'
});

it returns some text in ff, chrome and IE8, but in IE9 it shows twice "undefined".

I've looked into developer tool in IE9, and it showing a normal response so the request works fine, response is fine, but variables are undefined

headers of response:

Response    HTTP/1.1 200 OK
Cache-Control   no-cache
Content-Type    text/html; charset: UTF-8
Pragma  no-cache

response

string(4) "test"

解决方案

I suspect this is your problem:

Content-Type    text/html; charset: UTF-8

That value is not correctly formatted (the ':' after charset is wrong) and IE9 doesn't like it, but silently fails instead of saying something useful. Try this:

Content-Type:    text/html;charset=utf-8