Eventhough getData() doesn't return the new input, getDirty() correctly indicates that the contents of the editor changed since initialization, which makes it even weirder.
EDIT 2: Using the Safari Activity Log I observed that each time I perform the AJAX call, the CKEditor resources were being loaded again and again on top of the ones that were already there. Could my problem be caused by the fact that my original form elements still stay present somewhere in the DOM even after I inject new ones into the same div ? Or is that just a harmless side-effect of using AJAX ?
EDIT 3: I think I was able to trace down the problem to the instance not being destroyed. This doesn't look like intended behavior to me.
edinstance.destroy(); alert(edinstance.getData()); //Still returns the old contents of the editor
And the reason this is causing a problem seems to be because the instance is not being retrieved from the textarea the second time around.
edinstance = null; //Tried setting the instance variable to null before getting the new instance from the textarea edinstance = $('textarea#contents').ckeditorGet(); //This causes an error "edinstance is null"
This leads me to believe that even after replacing the innerHTML that includes the textarea, it is still available to CKEditor somehow. Since I'm using the id of the textarea, this could explain my problems.
EDIT 4: Ok this is beyond me... To make sure the editor was linked to the latest textarea I gave it a random id. I have verified that the instance is actually current, I can use every method and access any property EXCEPT FOR getData() even getSnapshot correctly returns all recent input while getData() doesn't, how is that even possible. If I use setData(), getData will start returning whatever I set, but it doesn't change the contents of the actual editor on the screen.
Background:
I have a form that is injected into the page with AJAX.
The form contains a textarea contents and it may already contain some content set in the PHP backend.
"<textarea id=\"contents\" class=\"article\">" . $articleContent->getBody() . "</textarea>"
I have a global javascript variable edinstance that I use to hold the current instance of CKEditor.
After the form is loaded I check if the global variable already contains an instance, if this is the case I destroy it. This is necessary to avoid conflicts because the form may be closed and reloaded several times without refreshing the full page.
I attach a new instance of CKEditor to the textarea and place it in the global
function attachEditor() { if(typeof edinstance != "undefined") { edinstance.destroy(); //alert('editor destroyed'); } $('textarea#contents').ckeditor(); edinstance = $('textarea#contents').ckeditorGet(); }Scenario:
1. I open the page
2. I perform the action that causes the form to be loaded
3. A new instance of CKEditor is attached to the textarea
4. I type some additional characters into the editor field and click the 'submit' button
5. edinstance.getData() correctly gets the contents of the editor as they currently are and passes them to the server with AJAX where they are saved.
6. I decide I want to edit the content some more so I reload the form again
7. The current instance in editorinstance is destroyed and a new one is attached to the textarea and stored in the global
8. I type some additional characters into the editor field and click the 'submit' button
9. edinstance.getData() returns the original contents of the textarea, ignoring my new additions. (Same for any subsequent attempt untill I refresh the full page).
Using .val() on the textarea does exactly the same, even after manually updating it with editorinstance.updateElement(). I have already confirmed that the instances are actually being destroyed and recreated. The problem is exactly the same in every browser I tested with (Fx 3.6, Safari 4.0, Chrome 11.0)
The only error I can catch is this always only on the second initialization, but on none of the subsequent ones.
i.contentWindow is null [] if(c){var u=n.getDocumentElement().con...on(){return this.$.childNodes.length; //ckeditor.js line 19
I've tried googeling this but couldn't find anything useful on this error in this context. I don't think it's actually related to my getData() problem. I'm starting to think it may be a caching issue with the iframe that CKEditor creates.
Any help, tips or experiences with a similar issue would be greatly appreciated
Re: getData() returns old contents after the first time (PHP
Could you publish a test case online?
Re: getData() returns old contents after the first time (PHP
While the issue isn't that urgent, I was hoping this would be a common problem due to some beginner oversight or something.
Using the Safari Activity Log I observed that each time I perform the AJAX call, the CKEditor resources were being loaded again and again on top of the ones that were already there. Could my problem be caused by the fact that my original form elements still stay present somewhere in the DOM even after I inject new ones into the same div ? Or is that just a harmless side-effect of using AJAX ?
Re: getData() returns old contents after the first time (PHP
Use .destroy(true) instead, that will do the cleanup correctly.

Hope this saves some time for someone (I've wasted a few hours searching for the same issue, little bit later found the answer there: http://dev.ckeditor.com/ticket/8226).
That's one really annoying problem, yet still not patched in the public release...
Re: getData() returns old contents after the first time (PHP
Oh, yes, here you are right, this problem makes me mad!!! Hopefuly smn will find the solution soon, otherwise I ...
Re: getData() returns old contents after the first time (PHP
so anyone who is getting frustrated on this issue just get the iframe data instead of using getData()
sample code
var iframe=$("iframe",parentnode);
var value=$("body",iframe.contents()).html();