您的位置:首页 > 产品设计 > UI/UE

EasyUI form ajax submit后,在IE下提示下载内容的解决办法

2012-10-22 21:22 567 查看
在IE下使用EasyUI form插件创建或编辑数据时(操作成功后会返回一段json),始终无法运行回调函数,而是提示下载内容。
在IE9下的提示如下图:为了解决这个问题,需要将json字符串用下面的格式返回给客户端才行。

<body>
<pre>{"message":"保存成功","data":null,"success":true}</pre>
</body>

所以写了一个hack方法:

View Code 1 /// <summary>
2 /// 前台Ajax请求的统一返回结果类
3 /// </summary>
4 public class AjaxResult
5 {
6 private AjaxResult()
7 {
8 }
9
10 private bool _isError = false;
11
12 /// <summary>
13 /// 是否产生错误
14 /// </summary>
15 public bool IsError { get { return _isError; } }
16
17 /// <summary>
18 /// 错误信息,或者成功信息
19 /// </summary>
20 public string Message { get; set; }
21
22 /// <summary>
23 /// 成功或失败时返回的数据
24 /// </summary>
25 public object Data { get; set; }
26
27 /// <summary>
28 /// 指示前台应该做什么操作
29 /// </summary>
30 public string Action { get; set; }
31
32 #region Error
33 public static AjaxResult Error()
34 {
35 return new AjaxResult()
36 {
37 _isError = true
38 };
39 }
40 public static AjaxResult Error(string message)
41 {
42 return new AjaxResult()
43 {
44 _isError = true,
45 Message = message
46 };
47 }
48 #endregion
49
50 #region Success
51 public static AjaxResult Success()
52 {
53 return new AjaxResult()
54 {
55 _isError = false
56 };
57 }
58 public static AjaxResult Success(string message)
59 {
60 return new AjaxResult()
61 {
62 _isError = false,
63 Message = message
64 };
65 }
66 public static AjaxResult Success(object data)
67 {
68 return new AjaxResult()
69 {
70 _isError = false,
71 Data = data
72 };
73 }
74 public static AjaxResult Success(string message, object data)
75 {
76 return new AjaxResult()
77 {
78 _isError = false,
79 Data = data,
80 Message = message
81 };
82 }
83 #endregion
84
85 public override string ToString()
86 {
87 return new JavaScriptSerializer().Serialize(this);
88 }
89
90 /*When using form ajax submit, the server response should be an HTML file with a textarea element or a pre element. The response data should be inside the textarea element or pre element. For example:
91 <body>
92 <pre>{"message":"保存成功","data":null,"success":true}</pre>
93 </body>
94 To retrieve the response data:
95 $('#ff').form({
96 success:function(data){
97 alert(data);
98 }
99 });
*/
public ActionResult ToActionResult()
{
var result = new ContentResult();
result.Content = string.Format("<body><pre>{0}</pre></body>", this.ToString());
result.ContentType = "text/html";
return result;
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐