English 中文(简体)
AJAX和Jquery
原标题:Saving tinymce editor with AJAX and Jquery
  • 时间:2012-04-05 01:25:42
  •  标签:
  • jquery
  • ajax

我已经阅读了与这一问题类似的问题,并且已经取得了相当的进展,但显然我的情况有所不同,因此我仍然试图说明这一点。

我有一份文本,与Tinymce html编辑作风格。 我希望文本雷阿能与阿富汗复兴共和与复兴共和军实现自动化。

我一直在制定法典,根据时间间隔节省案文:

$(document).ready(function() {

$(function() {
// Here we have the auto_save() function run every 30 secs
    // We also pass the argument  editor_id  which is the ID for the textarea tag
    setInterval("auto_save( editor_id )",30000);
iii

iii

// Here is the auto_save() function that will be called every 30 secs
function auto_save(editor_id) {

// First we check if any changes have been made to the editor window
    if(tinyMCE.getInstanceById(editor_id).isDirty()) {
    // If so, then we start the auto-save process
        // First we get the content in the editor window and make it URL friendly
        var content = tinyMCE.get(editor_id);
        var notDirty = tinyMCE.get(editor_id);
        content = escape(content.getContent());
        content = content.replace("+", "%2B");
        content = content.replace("/", "%2F");
        // We then start our jQuery AJAX function
        $.ajax({
        url: "PAFormAJAX.asp", // the path/name that will process our request
            type: "POST", 
            data: "itemValue=" + content, 
            success: function(msg) {
                alert(msg);
                // Here we reset the editor s changed (dirty) status
                // This prevents the editor from performing another auto-save
                // until more changes are made
                notDirty.isNotDirty = true;
            }
        iii
        // If nothing has changed, don t do anything
    } else {
        return false;
    }
}

这是行之有效的,但我的问题是,形式要素的形成是动态的,因此我并不总是静态编辑,我可以使用。 我怎么能够更新,以接受动态的国际发展动态。

例如,这里的案文中有一个与《公约》有活力地制定:

<textarea id="Com<%=QuesID%>" row= "1" cols= "120" name="Com<%=QuesID%>" QuesID="<%=QuesID%>" wrap tabindex="21" rows="10" class="formTxt"><%=TempTxt%></textarea>

此外,我试图指出一种办法,不仅在间隔时间,而且当用户点出文字区,而且分散重点时,就把储蓄功能称作“拯救功能”。 我不敢肯定如何做到这一点,因为锡奈斯岛从一个文字区改为一个明显明显的框架。

非常感谢任何帮助。

最佳回答
问题回答

this is excellent. I made a few changes because the post still was triggered multiple times. Also, now the auto_save timer is reset when a change is made:

$.status = function (message) {
    $( #statusMsg ).html( <p>  + message +  </p> );
};
$.status( log div );

$(document).ready(function () {
var myinterval;    

//for version 4.1.5 
    tinymce.init({
        selector:  textarea ,
        width: "96%",
        height: "200",
        statusbar: true,
        convert_urls: false,
        plugins: [
            "advlist autolink lists charmap print preview",
            "searchreplace fullscreen",
            "insertdatetime paste autoresize"
        ],
        toolbar: "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
        external_plugins: {"nanospell": "/Scripts/nanospell/plugin.js"},
        nanospell_server: "asp.net", // choose "php" "asp" "asp.net" or "java"

        setup: function (ed) {  //start a 30 second timer when an edit is made do an auto-save 
            ed.on( change keyup , function (e) {
                //clear the autosave status message and reset the the timers
                $.status(  );
                clearInterval(myinterval);
                myinterval = setInterval(function () {
                    for (edId in tinyMCE.editors)
                        auto_save(edId);
                }, 30000); //30 seconds
            });
        }
    });

    // Here is the auto_save() function that will be called every 30 secs
    function auto_save(editor_id) {
        var editor = tinyMCE.get(editor_id);
        if (editor.isDirty()) {
            var content = editor.getContent();
            content = content.replace("+", "%2B"); 
            content = content.replace("/", "%2F");
            $.ajax({
                type: "POST",
                url: "/PlanningReview/Save",
                data: "itemValue=" + content,
                cache: true,
                async: false,   //prevents mutliple posts during callback
                success: function (msg) {
                    $.status(msg)
                }
            });
        }
        else {
            return false;        // If nothing has changed, don t do anything
        }
    }
});

now you can create editors dynamically and give ** unique ids ** for each of them and get content for each id and store in ** array ** , later pass data to anywhere by making ajax call.

$(document).ready(function() {
    // Here we have the auto_save() function run every 30 secs
    // We also pass the argument  editor_id  which is the ID for 
    setInterval("auto_save()", 30000);
  
});

function auto_save() {
  var editorContents = [];

  for (var i = 1; i <= editorCount; i++) {
    var textareaId = "editorId" + i;
    //check if any changes have been made to the editor window
    if (tinyMCE.get(textareaId).isDirty()) {
      // Start the auto-save process
      // Get the content in the editor window and make it URL friendly
      var content = tinyMCE.get(textareaId);
      var notDirty = tinyMCE.get(textareaId);
      content = escape(content.getContent());
      content = content.replace("+", "%2B");
      content = content.replace("/", "%2F");

      // Add the editor to the array
      editorContents.push({
        id: textareaId,
        content: content,
      });
      notDirty.isNotDirty = true;
    } else {
      return null;
    }

    // now  u can store each editor content if it is changed  in array and pass  
    saveEditorContents(editorContents);
  }
}

function saveEditorContents(contents) {
  $.ajax({
    url: "PAFormAJAX.asp", // the path/name that will process our request
    type: "POST",
    data: JSON.stringify({
      EditorContents: contents
    }),
    success: function(msg) {
      alert(msg);
      // Here we reset the editor s changed (dirty) status
      // This prevents the editor from performing another auto-save
      // until more changes are made

    }
  });
}




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签