E
E
Evgeny Petrov2018-06-02 16:04:28
CKEditor
Evgeny Petrov, 2018-06-02 16:04:28

How to send texrarea content with ajax?

Editor initialization:

spoiler
ClassicEditor.create( document.querySelector('#add-page-content') )
  .then( editor => {console.log( editor );} )
  .catch( error => {console.error( error );} );

AJAX submission:
spoiler
var pageContent = $("#add-page-content").text();
$.post(url,'&method=pageСreate&pageName=1&pageContent='+pageContent,function(data) {
  data = JSON.parse(data);
  if (data['status'] == 1){
    alert('Страница успешно создана!');
  }else{
    alert('Произошла ошибка');
  }
});


PHP processing:
spoiler
if( $data['method']=='pageСreate' ){
  $pageContent = $data['pageContent'];
  $savePage = file_put_contents("1.html", $pageContent);
  if( $savePage ){
    echo json_encode(array('status' => '1'));exit();
  }else{echo json_encode(array('status' => '0'));exit();}				
}

As a result, an empty 1.html is created.
How to correctly transfer data from CKEditor 5?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question