开发者

zend jquery tinymce ajax save one step old value

I have form with Tinymce. I am saving text writen in tinyMce using ajax call. when I press the save button it does not save the latest value which i entered in tinymce. i.e. when i load the page, default value in the field is "aaaa". I update it to "bbb" and press the save button. but it saved the value "aaaa". Now I change the value from "bbb" to "ccc" and press the save button now it save the previous value "bbb" not "ccc". so it is keep saving the one step old value. I don't know why?

Here is the saveAction which I am calling on Save button using ajax

public function saveAction() {

$this->_helper->layout->disableLayout();        
$this->_helper->viewRenderer->setNoRender(true);    

var_dump ($_REQUEST);       
    if($this->getRequest()->isPost())
    {
        $data=$this->_getParam('content');

           var_dump(开发者_JS百科$_REQUEST); // var dump shows the old value each time i press the save button
     }

here is my form

here is ajax script

$('#frm').submit(function() { 
    var options = { 
        target:        '#response',   
        beforeSubmit:  showRequest,  
        success:       showResponse,  
    url: '/admin/index/save'
        };

  $(this).ajaxSubmit(options); 

  return false; 
    }); 

function showRequest(formData, jqForm, options) { 
var queryString = $.param(formData); 
}

function showResponse(responseText, statusText, xhr, $form)  { 
}


Try to do the following on button click before you anything else:

tinymce.activeEditor.save();

This will set the actual editor content to the textarea in the background.


Hi i searched alot about this then from tiny mce site i found this onkeyup event that can be added in the script code in head.

// Adds an observer to the onKeyUp event using tinyMCE.init
tinyMCE.init({
    ...
    setup : function(ed) {
      ed.onKeyUp.add(function(ed, e) {
          console.debug('Key up event: ' + e.keyCode);
      });
    }
});

I replaced some parts like below

tinyMCE.init({
    ...
    setup : function(ed) {
        ed.onKeyUp.add(function(ed) {
            tinymce.activeEditor.save();
        });
    }
});

so now whenever i change something in any tinymce textarea on my page the current text is saved and ajax get the current value.

I got my problem solved.

I am just a starter in ajax and JavaScript having a desire to achieve perfection.

I hope this helps others as well :)

Just remember me in your prayers.

Happy coding :)


tinyMCE.activeEditor.save();

(caps letters for MCE)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜