jquery ajax返回包含"\0"的"text"类型,IE下截断,FF chrome正常
时间:2011-11-28
来源:互联网
代码如下
$.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?
作者: pythen 发布时间: 2011-11-28
作者: ifandui 发布时间: 2011-11-28
[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;
}
}
}
作者: pythen 发布时间: 2011-11-28
试试text/html
作者: ifandui 发布时间: 2011-11-28
作者: pythen 发布时间: 2011-11-28
context.Response.Write("Hello \\0 World");
这样能显示\0这个字符本身
作者: p2227 发布时间: 2011-11-28
作者: ifandui 发布时间: 2011-11-28
作者: pythen 发布时间: 2011-11-28
<script> $.ajax({ type: "POST", datetype: "text", url: "/ashx/show.ashx", success: function (msg) { alert(msg.replace(/\\0/,"")); } }); </script>
作者: p2227 发布时间: 2011-11-28
这个时候,在IE下msg已经被截断了
作者: pythen 发布时间: 2011-11-28
msg.replace(/\\0/,"")
这个时候,在IE下msg已经被截断了
作者: p2227 发布时间: 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;
}
}
在重新编译你的项目试试看。。。
作者: IT_Kid 发布时间: 2011-11-28
这个时候msg已经只剩下"hello"
作者: pythen 发布时间: 2011-11-28
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28