Syntax for a function in order to get post’s title in JSON encoded response [closed]

You want to add the title to the response, not replace the response with the title. Like this:

<?php
function get_all_images($post_id=0, $size="bigger", $attributes="") {
    $post_id = $_POST['post_id'];
    if ($post_id<1) $postid = get_the_ID();
    if ($images = get_children(array(
        'post_parent' => $post_id,
        'post_type' => 'attachment',
        'numberposts' => -1,
        'orderby' => 'menu_order',
        'post_mime_type' => 'image',)))
            $title = get_the_title($post_id);
        $response="<h2 class="titles">".$title.'</h2>';
        foreach($images as $image) {
            $attachment=wp_get_attachment_image_src($image->ID, $size);
            $tranparent=get_template_directory_uri();

            $response .= '<img src="'.$tranparent.'/images/transparent.gif" data-original="'.$attachment[0].'" alt="" class="imarge" />';
        }
    die( json_encode( $response ) );
}?>

Update

Corrected to add it before the loop.