jquery ajax返回包含"\0"的"text"类型,IE下截断,FF chrome正常

pythen 2011-11-28 06:45:03

代码如下

$.ajax({
type:"POST",
datetype:"text",
url:"/ashx/show.ashx",
success:function(msg){
alert(msg);
}
});

show.ashx输出“Hello \0 World”,FF,chrome获取正常,IE只能获取“Hello",被“\0”截断,只考虑jquery的话,怎么兼容IE?
...全文
173 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
pythen 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 it_kid 的回复:]
把你的后台代码改成:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello \\0 World");
}

public bool IsReusable
{
……
[/Quote]

上面已经说了,修改后台的情况下这个问题就很简单。现在就是单纯讨论一下IE下截断的问题,因为FF,chrome都不存在这个问题
pythen 2011-11-28
  • 打赏
  • 举报
回复
断点查看,success: function (msg)

这个时候msg已经只剩下"hello"
偽妳變乖 2011-11-28
  • 打赏
  • 举报
回复
把你的后台代码改成:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello \\0 World");
}

public bool IsReusable
{
get
{
return false;
}
}
或者
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write(@"Hello \0 World");
}

public bool IsReusable
{
get
{
return false;
}
}


在重新编译你的项目试试看。。。
p2227 2011-11-28
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 pythen 的回复:]

msg.replace(/\\0/,"")

这个时候,在IE下msg已经被截断了
[/Quote]我的IE8没被截断,alert时候是截了
pythen 2011-11-28
  • 打赏
  • 举报
回复
msg.replace(/\\0/,"")

这个时候,在IE下msg已经被截断了
p2227 2011-11-28
  • 打赏
  • 举报
回复
<script>
$.ajax({
type: "POST",
datetype: "text",
url: "/ashx/show.ashx",
success: function (msg) {
alert(msg.replace(/\\0/,""));
}
});
</script>
pythen 2011-11-28
  • 打赏
  • 举报
回复
实际上"\0”这个是预期之外的字符,在不改动后台代码的情况下,在FF,chrome下可以处理掉,而在IE下却被"\0"截断,无法拿到原来的全部内容,如果要改动后台就很简单。顺带讨论一下出现截断这种情况的原因
默默不得鱼 2011-11-28
  • 打赏
  • 举报
回复
"Hello \\0 World"
p2227 2011-11-28
  • 打赏
  • 举报
回复
你是想要达到什么效果???
context.Response.Write("Hello \\0 World");

这样能显示\0这个字符本身
pythen 2011-11-28
  • 打赏
  • 举报
回复
还是不行
默默不得鱼 2011-11-28
  • 打赏
  • 举报
回复
context.Response.ContentType = "text/plain";
试试text/html
pythen 2011-11-28
  • 打赏
  • 举报
回复
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class show : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello \0 World");
}

public bool IsReusable
{
get
{
return false;
}
}
}
默默不得鱼 2011-11-28
  • 打赏
  • 举报
回复
我这边测试没有问题,你的服务器端代码帖出来吧 另外dataType 大写的T

87,921

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧