一覧画面で「プレビュー」ボタンを押すとポップアップ(Modal)でその内容が表示されます。
行の先頭の管理番号をピックアップしてAjaxで飛ばしてそのデータをModal Windowに表示をします。
このとき、開発ツールではPOSTされているはずなのに、受け取りのPHP側では受け取れていないようなのです。
原因が全く分からず、困っています。成功した過去のデータをコピペで利用しているのですが、挙動が同じようになりません。
よろしくお願いいたします。
Html(Table部分)
<table class="table"> <tbody> <tr> <th>管理番号</th> <th>タイトル</th> <th>対象日</th> <th>表示・非表示</th> <th>画像</th> <th>主要データ</th> <th></th> <th></th> </tr> <tr><td><span>16</span></td><td>10月15日 井の頭公園イベント -ムツゴロウさん</td><td>2017年10月08日</td><td>公開</td><td><button type="button" onclick="location.href='/ctrl/blog_imgs_update/16'" class="btn btn-warning">更新</button></td><td><button type="button" onclick="location.href='/ctrl/blog_info_update/16'" class="btn btn-success">更新</button></td><td><a class="btn btn-large btn-danger" data-toggle="confirmation" data-title="削除しますか?" href="/ctrl/delete_blog/16">削除</a></td><td><button type="button" class="preview_blog btn btn-primary">プレビュー</button></td></tr> (中略) </tbody> </table>
JS
//ボタンをクリック $('.preview_blog').click(function(){ var id = $(this).closest('tr').find('td:first span').html(); $.ajax({ type: "POST", url: "/admin/afu007", data: {"id":id}, dataType: "json", cache: false, success: function(data, status){ $('#Preview_Blog').modal(); //ここに受け取ったデータの埋め込み処理 }, error: function(XMLHttpRequest, status, errorThrown){ alert("エラーが発生しました!"); } }); });
Controller
public function index(){ //POSTデータ $ary = $this->afmu007->Get_Detail_Data(); echo json_encode($ary); }
Model
//取得 function Get_Detail_Data(){ $array = array(); $post_array = array(); $post_array = $this->input->post(); echo "<pre>"; print_r($post_array); echo "</pre>"; array_push($array,$post_array["id"]); //結果を取得して表示する $sql = " select id as id,title_blog as title_blog,"; $sql .= "contents as contents,pub_flg as pub_flg,youtube_prm as youtube_prm,message_movie as message_movie,"; $sql .= "DATE_FORMAT(date_public,'%Y年%m月%d日') as date_public,"; $sql .= "DATE_FORMAT(regist_date,'%Y年%m月%d日') as regist_date"; $sql .= " from blog"; $sql .= " where id = ? "; $query = $this->db->query($sql,$array); $ary = array(); if($query->num_rows() > 0){ foreach($query->result() as $row){ $ary["title_blog"] = $row->title_blog; $ary["contents"] = $this->br2nl($row->contents); $ary["youtube_prm"] = $row->youtube_prm; $ary["message_movie"] = $row->message_movie; $ary["date_public"] = $row->date_public; $ary["regist_date"] = $row->regist_date; //公開・非公開 switch($row->pub_flg){ case 0: $ary["pub_flg"] = "非公開"; break; case 1: $ary["pub_flg"] = "公開"; break; default: $ary["pub_flg"] = "非公開"; break; } } } return $ary; }
Model側のPOST Data の id が取得できません。
開発ツールを利用したりしてるのですが、原因がつかめません。
宜しくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/10/11 05:16
2017/10/11 05:18
2017/10/11 06:15