How to send html using json

I am creating a plugin for wordpress and I want to manage the curriculum of an Institute. I use fullcalendar in order to display the records from the database, using json. The problem is that I want to create edit and delete buttons on every event (simple links). I try to send html code with json, but I get the html tags as text in the browser page.

Is there a way to add working html to my json?

<?php
//json response view lessons
add_action('wp_ajax_utt_json_calendar','utt_json_calendar');
function utt_json_calendar(){
    global $wpdb;
    $viewType = $_POST['viewType'];
    $viewFilter = $_POST['viewFilter'];
    $lessonsTable = $wpdb->prefix."utt_lessons";
    $lessons = $wpdb->get_results("SELECT * FROM $lessonsTable WHERE classroomID=$viewFilter;");
    $jsonResponse = array();
    foreach($lessons as $lesson){
        $result[title] = $lesson->lessonID."<a href='#'>asd</a>";
        $result[start] = $lesson->datetime;
        array_push($jsonResponse,$result);
    }
    echo json_encode($jsonResponse);
    die();
}
?>

Related posts

Leave a Reply

1 comment

  1. Fullcalendar queries that php script and expects text for event.title.

    If you want to add links to your events, you need to do this in your FullCalendar options (Javascript).

    The FullCalendar option you are looking for is eventRender. It should look something like:

    eventRender: function(event, element) {
        element.find('.fc-title').append($("<a href='#'>"+event.editlink+"</a>"));
    }
    

    It’ll look like this fiddle.

    And in your PHP, add the property editLink (or whatever you want to name it) to your returned JSON:

    foreach($lessons as $lesson){
        $result[title] = $lesson->lessonID;
        $result[start] = $lesson->datetime;
        $result[editLink] = "asd"; //you could use HTML here but it's better in JS
        array_push($jsonResponse,$result);
    }
    

    There really isn’t any way to do what you want only in PHP since you have to modify the FullCalendar options (which has to be done in JS)
    .