简单返回json格式字符串的问题

net205 2009-12-01 05:53:43
我在写代码时发现一个不解的问题,在此请教大家。

程序是使用jquery插件jquery.form向服务器端提交表单,服务器端操作完成后返回json格式的字符串。
程序类似下面的简单代码:

test.aspx:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://jquery.malsup.com/jquery-1.3.2.js"></script>
<script type="text/javascript" src="http://jquery.malsup.com/form/jquery.form.js"></script>
<script>
jQuery(document).ready(function() {
$('#frmUpload').ajaxForm({
url: 'return.aspx',
type: 'post',
dataType: 'json',
success: function(data) {
alert(1)
alert(data)
return false;
}
});
});
</script>
</head>

<body>
<form id="frmUpload" name="frmUpload" enctype="multipart/form-data" method="post" action="return.aspx">
<input type="file" id="upload" name="upload" size="50" />
<input id="upload" name="upload" type="submit" value="upload" title="upload" />
</form>
</body>
</html>



return.aspx:

<%
HttpContext.Current.Response.ContentType = "text/plain";
HttpContext.Current.Response.Charset = "utf-8";
Response.Write("{error: false, message: 'no files !'}");
%>


就这样一个简单代码,在IE7/IE8/FF下都正常,但在IE6下却出现错误。

演示步骤:
1、保存上面两个文件的代码,在IE6中浏览test.aspx页面,点击upload按钮,会发现没反应的。
2、把test.aspx页面中dataType: 'json',一行注释掉,再访问点击upload按钮,会弹出1和return.aspx页面结果。 但是这个return.aspx页面结果有问题:

无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试
文档的顶层无效。处理资源 'http://localhost/return.aspx' 时出错。第 1 行,位置: 1

3、如果保留test.aspx页面中的dataType: 'json',一行(即不注释),然后注释掉return.aspx页面的第一行。返回结果正常,达到预想的效果。



问题:在return.aspx页面中指定了类型为text/plain,输出json格式的字符串,可是在IE6中为为什么以xml格式下解析?
...全文
871 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
net205 2009-12-03
  • 打赏
  • 举报
回复
伤心啦,CSDN上的问题越来越没人理了..
liherun 2009-12-02
  • 打赏
  • 举报
回复
json还没学会
net205 2009-12-02
  • 打赏
  • 举报
回复
怎么没人理呀???
net205 2009-12-01
  • 打赏
  • 举报
回复
这儿有同样的问题:http://topic.csdn.net/u/20070120/16/18148e05-1022-4389-96c3-edf141d770ed.html

就是不知道为什么会这样????

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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