###前提・実現したいこと
Cakephpで投稿サイトを作っています.
###発生している問題・エラーメッセージ
Userページに削除ボタンを設置し,そのボタンを押すと削除用のactionが作動し,該当postの削除が出来るように作ったつもりなんですが,動きません.
デベロッパーツールで見てみると,500INternal server error となっていました.
###該当のソースコード
php
1<!-- 削除ボタン --> 2<button href="#" 3 class="delete" data-post-id="<?php echo h($posted['id']) ?>">削除</button> 4 5<script> 6 $('button.delete').click(function(e) { 7 if (confirm('削除しますか?')) { 8 $.post('/users/users/delete/'+$(this).data('post-id'), {}, function(res) { 9 //一部分だけ変える 10 //$('#post_'+res.id).fadeOut(); 11 }, "json"); 12 } 13 return false; 14 }); 15</script>
UsersController.php
1public function delete($id) { 2 if ($this->request->is('get')) { 3 throw new MethodNotAllowedException(); 4 } 5 6 if ($this->request->is('ajax')) { 7 $this->autoRender = false; 8 $this->autoLayout = false; 9 $this->Post->id = $id; 10 if ($this->Post->delete()) { 11 $response = array('id' => $id,'idd'=>true); 12 $this->header('Content-Type: application/json'); 13 echo json_encode($response); 14 exit(); 15 } 16 } 17 $this->redirect(array('action'=>'index')); 18 }
###試したこと
DBがきちんと作られていることは確認しました.
ネットの情報を基に.htaccessを変更してみました.
###補足情報(言語/FW/ツール等のバージョンなど)
確認しているブラウザはChromeで,デベロッパーツールのConsoleから見ると,以下の記述がありました.
jquery.min.js:4 POST http://localhost/posts/delete/6 500 (Internal Server Error)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
f.(anonymous function) @ jquery.min.js:4
(anonymous function) @ (index):474
dispatch@ jquery.min.js:3
i @ jquery.min.js:3
あなたの回答
tips
プレビュー