I am working on a plugin, my very first plugin. I want to get the post content when ever a change happen in the wp_editor.

I am able to get the content, but for that i have to reload the post page. I want to do it without reloading the page. I know ajax will be used but i have no idea about ajax, i did plenty of search but unable to find a solution or tutorial.

below code is the my working code as mentioned earlier, that it requires page to reload inorder to update “$var_post_content”.

     global $post_id;
     $var_post_content = get_post_field('post_content', $post_id);
     echo $var_post_content;

I want this { $var_post_content } to be updated automatically.
ajax would be something like this:

        url : ajaxurl,
        type : 'POST',
        dataType: 'json',
        data : {
                    // i guessing that this part will be used to get some data
        } ,
        'success' : function(data){
            // this might update the variable.

Read more here: I want to update php variable when any change occurs in the wp_editor


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: