HTML tags is being escaped

I have an editor that I am saving and loading content dynamically as user creates multiple templates. Problem I am having is that I am able to load all fields like name of the template and subject etc, the only thing that I can’t save and load correctly is the content for the editor.

This is the AJAX post method on how I send the content:


$("body").on("click", ".nav-tabs li a", function () {

        var data = $('#campaign-form').serialize();

        var sHTML = $('[id^=htmlEditor]').data('contentbuilder').html();

   

        $.ajax(

            {

                dataType: 'html',

                type: 'POST',

                url: "campaigns/sequenceupdate",

                data: data + '&contentHTML=' + sHTML,

                success: function (response) {

                    var jsonResponse = $.parseJSON(response);

                   

                    $("div[id^=htmlEditor]").data("contentbuilder").loadHTML(jsonResponse.templateContent);


                }

            }

        )

    });

then on the server I save the content for the tab that was active then I load the content for the tab that was clicked. I am using only one form because I couldnt get the multiple editors to work:




     public function actionSequenceUpdate(){

        $request    = Yii::app()->request;




        $tabBeforeClicked = $_POST['tabBeforeClick'];

        $campaignBeforeClicked   = $this->loadCampaignModel($tabBeforeClicked);


        $tabClicked = $_POST['tabClicked'];

        $campaignClicked   = $this->loadCampaignModel($tabClicked);


        if ($request->isPostRequest && ($attributes = (array)$request->getPost($campaignBeforeClicked->modelName, array()))) {

            $campaignBeforeClicked->attributes = $attributes;

            if ($campaignBeforeClicked->save(false)) {

            }

            $template = $campaignBeforeClicked->template;


            $template->attributes=$_POST['CustomerEmailTemplate'];

            $template->content = $_POST['contentHTML'];

            $template->save(false);

        }


        $clickedTemplate = $campaignClicked->template;


        echo json_encode(array( "templateContent"=>$clickedTemplate->content));


    }

My problem is that that when I console.log the sHTML I get the correct data which looking like this:


  <table style="border: none; width: 90%; max-width: 980px; border-collapse: collapse; padding-top: 10px; padding-bottom: 10px; margin-left: auto; margin-right: auto; font-size: 2em; clear: both; margin-top: -10px; line-height: 1;"><tbody><tr>

    <td style="padding-left: 1rem; padding-right: 1rem; box-sizing: border-box; width: 100%; font-size: 1em;">

    <p style="text-align: center; font-size: 1.07em; line-height: 1; font-weight: 300; margin: 1em 0px;"><span style="font-size: 12px;">To unsubscribe from this list, please use this link:</span><span style="font-size: 12px;"><br>[UNSUBSCRIBE_URL]</span></p>

    <p style="text-align: center; font-size: 1.07em; line-height: 1; font-weight: 300; margin: 1em 0px;"><span style="font-size: 12px;">[COMPANY_FULL_ADDRESS]</span></p></td>

    </tr></tbody></table>

but on server side the content is saved like this:


{"templateContent":"\n\n\n\n\n\n\n\n\n\n\n\n\n\n \n\nTo unsubscribe from this list, please use this link:[UNSUBSCRIBE_URL]\n[COMPANY_FULL_ADDRESS]\n"}

I am not understanding why I am getting \n\n\n\n instead of the raw HTML and CSS, can someone please help