cakephp2.xにて
jqueryにjsonでデータを送っています。
現在、データは、送れているのですが、
自分の投稿したデータのみ削除ボタンを作成したいため
どこかで、ログインユーザのデータを送りたいのですが、
どういった方法が考えられるでしょうか。
jsonは、以下のコードから取得しています。
php
1public function json_data(){ 2 //$this->autoRender = FALSE; 3 $this->loadModel('Tweet'); 4 $this->loadModel('Follow'); 5// if($this->request->is('ajax')){ 6 $id=$this->Auth->user('username'); 7 //フォロワーをfind指定 8 $all_follow=$this->Follow->list_all_follow($id); 9 $json_data=$this->Tweet->json_alluser_tweet_all($all_follow,$id); 10 //debug($json_data); 11 $this->viewClass = 'Json'; 12 $this->set(compact('json_data')); 13 $this->set('_serialize','json_data'); 14/* } 15else { 16 throw new BadRequestException(); 17}*/ 18} 19 20--model-- 21public function json_alluser_tweet_all($all_follow,$id){ 22 $option = array( 23 'order' => array('Tweet.tweettime' => 'desc'), 24 'conditions'=>array('or'=>array(array('Tweet.name'=>$all_follow),array('Tweet.name'=>$id)))); 25 $tweet=$this->find('all',$option); 26 return $tweet; 27}
javascript
1$(document).ready(function(){ 2 $.ajax({ 3 type: "POST", 4 url: '/users/json_data', 5 dataType: 'json', 6 success : function(data){ 7 for(var i in data){ 8 $("#output").append(data[i].Tweet.name+"</br>"); 9 $("#output").append(data[i].Tweet.tweet+"</br>"); 10 $("#output").append(data[i].Tweet.tweettime+"</br></br>"); 11 /*if(json_username==data[i].Tweet.name){ 12 alert('通信失敗'); 13 }*/ 14 15}; 16 }, 17 error: function(){ 18 //通信失敗時の処理 19 alert('通信失敗'); 20 21 } 22 }); 23}); 24
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/20 18:28