dosryjij88555 2014-07-18 08:41
浏览 41

如何使用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?

  • 写回答

1条回答 默认 最新

  • dss89001 2014-07-18 08:53
    关注

    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 :-)

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号