代码如下$.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?

解决方案 »

  1.   

    我这边测试没有问题,你的服务器端代码帖出来吧 另外dataType 大写的T
      

  2.   

        [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;
                }
            }
        }
      

  3.   

    context.Response.ContentType = "text/plain";
    试试text/html
      

  4.   

    你是想要达到什么效果???
    context.Response.Write("Hello \\0 World");这样能显示\0这个字符本身
      

  5.   

    实际上"\0”这个是预期之外的字符,在不改动后台代码的情况下,在FF,chrome下可以处理掉,而在IE下却被"\0"截断,无法拿到原来的全部内容,如果要改动后台就很简单。顺带讨论一下出现截断这种情况的原因
      

  6.   

    <script>
        $.ajax({
            type: "POST",
            datetype: "text",
            url: "/ashx/show.ashx",
            success: function (msg) {
                alert(msg.replace(/\\0/,""));
            }
        });
    </script>
      

  7.   

    msg.replace(/\\0/,"")这个时候,在IE下msg已经被截断了
      

  8.   

    我的IE8没被截断,alert时候是截了
      

  9.   

    把你的后台代码改成:
            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;
                }
            }
    在重新编译你的项目试试看
      

  10.   

    断点查看,success: function (msg)这个时候msg已经只剩下"hello"
      

  11.   


    上面已经说了,修改后台的情况下这个问题就很简单。现在就是单纯讨论一下IE下截断的问题,因为FF,chrome都不存在这个问题