//Your view action:
<?php
function index() {
//Provide your pagination info..
$this->set('entries', $this->paginate());
}
?>
//Your delete action:
<?php
function delete($id) {
$this->autoRender = false;
if ($this->Blog->delete($id)) {
$response = array("success" => true);
} else {
$response = array("success" => false);
}
return json_encode($response);
}
?>
//Your index.ctp
.....
<?php foreach ($entries as $entry): ?>
<div class="record">
<a href="<?php echo $this->Html->url(array("controller" => "blog", "action" => "delete", $entry['Blog']['id'])) ?>" class="delete">Delete</a>
<strong><?php echo $entry['Blog']['title'] ?></strong>
</div>
<?php endforeach; ?>
//Your Javascript
<script type="text/javascript">
$(document).ready(function() {
$('a.delete').click(function(e) {
var __this = this;
e.preventDefault();
var parent = $(this).parent();
$.ajax({
type: 'get',
url: $(__this).attr("href"),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function(response) {
//Changed here
response = $.parseJSON(response);//console.log(response);
if(response.success){
parent.slideUp(300,function() {
parent.remove();
});
}else{
alert("Failed to delete message");
parent.animate({'backgroundColor':'#fff'},100);//Restore your background back
}
}
});
});
});
</script>
:-) 여기에 어떤 포인터에 대한
많은 감사는 경고 :이 cake2 및하지만 POSTLINK() 작동하지 않습니다. 적 최첨단 버전을 사용할 계획이라면 :) – mark
그냥 궁금 해서요, 케이크 2.0에서는 작동하지 않겠습니까? – Mo3z
당신의 대답에 그것을 추가해야합니다 - 당신은 mcgarriers가 cake <2.0을 사용하고 있다고 가정하고 있습니다 (아마 맞을지라도). cake2는 기본 게시물 링크를 사용하여 약간 더 어렵습니다. – mark