Content can get programmatically using the API method editor.getContent
.
// call editor
let app = Redactor('#entry');
// get content from outside scripts
let content = app.editor.getContent();
// get content in the plugin method
let content = this.app.editor.getContent();
See more how the API works.
You can get content from the editor as a JSON object.
To do this, use getJson
method.
// call editor
let app = Redactor('#entry');
// get content from outside scripts
let data = app.editor.getJson();
// get content in the plugin method
let data = this.app.editor.getJson();
See more how the API works.
The editor can send a save request for each change in the content.
To do this, specify the setting for the server-side script that will catch the saving of content.
Redactor('#entry', {
autosave: {
url: '/savedata-server-script/'
}
});
See a detailed description of autosave in the settings.
If the textarea
element for which the editor is running is in a form, then you can send content along with the form.
<form action="/savedata-server-script/" method="post">
<textarea id="entry" name="content"></textarea>
<button>Send</button>
</form>
<!-- call -->
<script>
Redactor('#entry');
</script>
You can send content as a POST request using AJAX, for example, with jQuery.
<!--form -->
<form action="" id="myform" method="post">
<!-- element -->
<textarea id="entry" name="content"></textarea>
<!-- submit button -->
<button onclick="sendForm();">Send</button>
</form>
<!-- call -->
<script>
Redactor('#entry');
</script>
<!-- send data using jQuery -->
<script>
function sendForm() {
$.ajax({
url: '/savedata-server-script/',
type: 'post',
data: $('#myform').serialize()
});
}
</script>