EasyUI form ajax submit后,在IE下提示下載內容的解決辦法


 

在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 {  getset; }
 21 
 22          ///   <summary>
 23           ///  成功或失敗時返回的數據
 24           ///   </summary>
 25           public  object Data {  getset; }
 26 
 27          ///   <summary>
 28           ///  指示前台應該做什么操作
 29           ///   </summary>
 30           public  string Action {  getset; }
 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          });
100           */
101          public ActionResult ToActionResult()
102         {
103              var result =  new ContentResult();
104             result.Content =  string.Format( " <body><pre>{0}</pre></body> "this.ToString());
105             result.ContentType =  " text/html ";
106              return result;
107         }
108     }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM