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;
}
}
在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;
}
}
相关文章推荐
- EasyUI form ajax submit后,在IE下提示下载内容的解决办法
- EasyUI form ajax submit到MVC后,在IE下提示下载内容的解决办法
- 解决EasyUI Form submit和SpringMVC返回JSON在IE中变下载的问题
- 解决IE下AjaxSubmit上传文件提示下载文件问题
- 解决ie下ajaxsubmit上传文件提示下载文件问题
- JQuery EasyUI form ajax 提交后办事器返回操纵成果,IE提示下载
- form.js插件 利用ajaxSubmit上传文件时ie总出现下载提示框
- JQuery EasyUI form ajax 提交后办事器返回操纵成果,IE提示下载
- EasyUI form submit success方法失效,且在IE下提示下载内容的解决办法
- 解决ie下ajaxsubmit上传文件提示下载文件问题
- ajaxform 提交,返回JSON时,IE提示下载的问题解决
- Jquery form.js文件上传返回JSON数据,在IE下提示下载文件的解决办法,并对返回数据进行正确的解析
- 电驴提示“该内容尚未提供权利证明,无法提供下载”之解决办法详解
- Spring MVC避免IE提示下载返回的JSON 数据——解决办法
- .NET easyui form提交后,返回json数据在IE下弹出下载的问题解决方法
- Windows 2008 R2 标准版 ie提示 当前安全设置不允许下载该文件 解决办法
- 解析:使用easyui的form提交表单,在IE下出现类似附件下载时提示是否保存的现象
- PHP IE下载时提示”无法复制 无法读取源文件或磁盘”的解决办法
- IE下AjaxForm上传文件直接提示下载的兼容性Bug
- 电驴提示“该内容尚未提供权利证明,无法提供下载”之解决办法详解