如何将 JQuery ajaxForm 与 nicEdit 一起使用?

发布于 2024-08-17 06:54:37 字数 378 浏览 4 评论 0原文

我正在使用 ajaxForm 函数提交也具有 nicEdit html 编辑器的表单,但是当我第一次尝试提交表单时,不包含 nicEdit 的内容...有没有办法可以拦截提交的数据这样我就可以编辑表单数据了?或者在实际提交之前向表单数据添加值?类似...

var options = { 类型:'废话', 成功:巴拉巴拉, beforeSerialize:更改数据 } $('bla').ajaxForm(options)

函数 alterData(formdata){ // 就像在这里添加数据一样 formdata['newdata'] = 我是一个新数据! // 然后返回新的表单数据进行提交 返回表单数据; ?

有类似的东西吗 感谢所有的帮助...

I am using ajaxForm function to submit my form that has nicEdit html editor as well but when I tried to submit the form for the first time the content of the nicEdit is not included... Is there a way that I can intercept the data submitted so I can edit the form data? or maybe add values to the form-data before it actually gets submitted? something like...

var options = {
type: 'blahblah',
success: blahblah,
beforeSerialize: alterData
}
$('bla').ajaxForm(options)

function alterData(formdata){
// like adding a data here
formdata['newdata'] = im a new data!
// then return the new form data for submit
return formdata;
}

is there something similar to this? Appreciate all the help...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长途伴 2024-08-24 06:54:37

好吧,我在发布这篇文章后一个小时前就想出了这个问题,所以如果有人遇到同样的问题,这里就是解决方案:

确实有一个 beforeSerialize 选项!

...
beforeSerialize: alterData
...

function alterData(formData,options){
  var nicEdit_content = nicEditors.findEditor('id_of_textarea').getContent();
   formData.each(function(){
        $(this).find('#gth_text').val(nicEdit_content);
    })
  return true; // Return true to go back to  normal processing!
}

它对我有用!您可能可以使用其他在线 html 编辑器(例如 fckeditor、tinymce blah blah)执行相同的操作。

Well I figured it out just an hour ago after posting this, so if anyone has the same problem here is the solution:

there really is a beforeSerialize option!

...
beforeSerialize: alterData
...

function alterData(formData,options){
  var nicEdit_content = nicEditors.findEditor('id_of_textarea').getContent();
   formData.each(function(){
        $(this).find('#gth_text').val(nicEdit_content);
    })
  return true; // Return true to go back to  normal processing!
}

it works for me! You can probably do the same with other online html editors such as fckeditor,tinymce blah blah..

伴梦长久 2024-08-24 06:54:37

你可以用这个...
我已经尝试过了并且它有效..:)

例如对于文件上传,我替换了 addForm 函数...

 nicURI : 'upload-foto.php', <!-- for upload, just echo for response file path -->

 addForm : function() {

 var formHTML = '<div id="pageForm"><form method="post" action="'+this.uri+'"><div style="font-size: 14px; font-weight: bold; padding-top: 5px;">Insert an Image</div><input id="upload_foto" name="upload_foto" type="file" style="margin-top: 10px;" /></form></div><div id="pageLoad" style="display: none;"><img src="http://files.nicedit.com/ajax-loader.gif" style="float: right; margin-right: 40px;" /><strong>Uploading...</strong><br />Please wait</div>';

 var goo = this;
 this.ne.selectedInstance.restoreRng();

 $(function() { 

   $(this).find('#forUpload').append(formHTML);

   $(this).find('#forUpload').find('#upload_foto').change(function(data) { 

     var thiP = $(this);
     $(this).parents('#forUpload').find('#pageForm').hide();
     $(this).parents('#forUpload').find('#pageLoad').show();

     $(this).parents('form').ajaxForm(function(data) { 

        thiP.parents('#forUpload').find('#pageForm').show();
        thiP.parents('#forUpload').find('#pageLoad').hide();
        var tmp = data;
        goo.ne.nicCommand("insertImage",tmp);
        goo.im = goo.findElm('IMG','src',tmp);

     }).submit();


   });
 });

 },

you can use this...
I've already tried and it works.. :)

for example for file upload, i replace addForm function...

 nicURI : 'upload-foto.php', <!-- for upload, just echo for response file path -->

 addForm : function() {

 var formHTML = '<div id="pageForm"><form method="post" action="'+this.uri+'"><div style="font-size: 14px; font-weight: bold; padding-top: 5px;">Insert an Image</div><input id="upload_foto" name="upload_foto" type="file" style="margin-top: 10px;" /></form></div><div id="pageLoad" style="display: none;"><img src="http://files.nicedit.com/ajax-loader.gif" style="float: right; margin-right: 40px;" /><strong>Uploading...</strong><br />Please wait</div>';

 var goo = this;
 this.ne.selectedInstance.restoreRng();

 $(function() { 

   $(this).find('#forUpload').append(formHTML);

   $(this).find('#forUpload').find('#upload_foto').change(function(data) { 

     var thiP = $(this);
     $(this).parents('#forUpload').find('#pageForm').hide();
     $(this).parents('#forUpload').find('#pageLoad').show();

     $(this).parents('form').ajaxForm(function(data) { 

        thiP.parents('#forUpload').find('#pageForm').show();
        thiP.parents('#forUpload').find('#pageLoad').hide();
        var tmp = data;
        goo.ne.nicCommand("insertImage",tmp);
        goo.im = goo.findElm('IMG','src',tmp);

     }).submit();


   });
 });

 },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文