如何使用php显示对弹出窗口的数组响应

I have used a ajax call to a php function in codeigniter. After getting result I need to show that in a popup in same page. Now I am not able to show as it comes in an array. Below is my codeigniter controller function. I don't think my codes are correct.

    public function print_details1() {
    $this->isLoggedIn();
    $id = $_POST['id'];
    $response = $data['notifications'] = $this->file_model->print_view_detail($id);
    echo json_encode($response);
}

And ajax request is this

$.ajax({
    url: "" + baseurl + "/file/print_details1",
    async: false,
    type: "POST",
    dataType: "html",
    cache: false,
    data: {id: getvalue},
    success: function(response) {

        $('#myModal2').modal('show');

    }
});

My popup id is myModal2. And I have given below code inside popup.

<?php
  foreach ($response as $notification) {

  echo $notification->publication_name; 
} ?>

Now getting an error while checking using firebug. "Undefined variable: response" and "Invalid argument supplied for foreach()" What is wrong with this?

You're mixing PHP and HTML/jQuery. Below is some pseudo code to show you the right flow of how you should do this.

Lets say your modal has a div with an id like this:

<div id="#content"></div>

Now in your ajax success() function you want to loop through and itterate to the #content

.success(function(response){
    $.each(response, function(i, item){
       $('#content').append(item);
    });

    $('#myModal2').modal('show');
});

REMEMBER The above is pseudo code, you'll have to work out the kinks by yourself, but that shows you the general flow of how you should go about it :-)