An existing AJAX script which calls database content into a file is then passed via JS to a textarea, which was the old way. I replaced the textarea with FCK but am getting an FCKEditorAPI is not defined error. Here are the scripts used.
I have the following line of code at the bottom of the page, after everything else:
var FCK = FCKeditorAPI.GetInstance('body');
This button executes the AJAX to call the database and retrieve the necessary article data
<input type="button" name="loadarticle" id="loadarticle" value="Load Article Into Body" onClick="preFill(document.getElementById('article').value)">
Just below this I have the location of the FCKEditor to load into the browser:
<label>Body</label> <div id="bodywrap"> <? $oFCKeditor = new FCKeditor('body') ; $oFCKeditor->BasePath = 'fckeditor/'; $oFCKeditor->Value = stripslashes($body); $oFCKeditor->Width = '750' ; $oFCKeditor->Height = '400' ; $oFCKeditor->Create() ; print 'Tip: Use Ctrl+Enter for line breaks'; ?> </div>
These two functions retrieve the data and fill in the (previously used) textarea. You'll see that I'm trying to pass the global instance of the FCKEditor below in the handleFill function:
function preFill(art) { document.getElementById('msg').innerHTML="Prefill"; http = createRequestObject(); http.open('get', 'prefill.php?art='+art); http.onreadystatechange = handleFill; http.send(null); } function handleFill() { showedit(); if(http.readyState == 4){ if (http.status==200) { var response = http.responseText; if (response!="FAILURE") { FCK.setHTML(response); //document.forms.addcomponent.body.value = response; //message ("settings saved"); } else { alert("content not filled"); message("content not filled"); } } else { message('Error: content not received; '); } } }
No matter where I set var FCK = FCKeditorAPI.GetInstance('body'), I either get an error that this doesn't exist. Also note that this code is below where the FCKeditor loads to the browser, too.
Re: Problem setting editor content via AJAX
The FCKeditor docs recommend using FCKeditor_OnComplete, which only triggers when the editor is fully loaded. See the JavaScript API docs...