用jquery.form异步提交页面时,服务器端取不到Ueditor的值

来源:互联网 发布:部落冲突7级哥布林数据 编辑:程序博客网 时间:2024/05/10 23:39
根据Ueditor的帮助说明,默认情况下在服务器端或者Ueditor的值是Request.Form["editorValue"]。
1.在没有使用Jquery.form插件的情况下,点击页面的submit,是可以取到值的;
2.在使用Jquery.form插件异步提交页面的时候,发现点击submit之后,用firebug查看post信息,里面找不到editorValue,所以在服务端总是取不到Ueditor的值。
解决办法:
在页面form里添加一个hidden,在submit之前用editor.getContent()获取编辑器的值,并赋给这个hidden;
使用Jquery.form插件需要注意:不能再beforeSubmit在个事件中执行上面的操作,虽然也是在执行submit之前,但是提交到服务器端这个hidden还是没有内容的。

部分代码如下:


 

   <script language="javascript" type="text/javascript">      var editor;      $(document).ready(function() {         editor = new baidu.editor.ui.Editor();         editor.render("myEditor");              });           function processJson(data) {         if (data.status == "true") {            top.$.messager.alert('提示信息', data.msg, 'info', function() {               top.closeTab("页脚说明");                         });                     }         else {            top.$.messager.alert('提示信息', data.msg, 'error');         }      }      function SetVal() {         var options = {            url: "FootInfo.aspx?ps=SAVE",            type: "post",            dataType: "json",            success: processJson         };         $("#myContent").val(editor.getContent()); //或者编辑器的值要写在这里或者上面,不能写在beforeSubmit事件里         $("#formPost").ajaxSubmit(options);      }   </script> 


<form id="formPost" method="post" action="">   <input type="hidden" id="myContent" name="myContent" />   <div id="content">       <ul>         <li id="editor" style="height:320px;">            <label for="myEditor" style="vertical-align: top">               页脚描述:            </label>             <textarea id="myEditor"> <%=strSummary %></textarea>           </li>      </ul>      <div  class="pt10 pl125">         <a id="btnSave" href="javascript:void(0)" onclick="SetVal()" class="btn_yl mr10"><span>            <span class="fc_42">保存</span> </span></a>      </div>         </div>   </form>