cakephp.Itries에서 jquery로 레코드를 삭제할 때 다음 코드가 표시되지만 실제 출력을 제공하지 않습니다. 페이지를 새로 고칠 때 레코드가 삭제됩니다. 삭제 링크를 클릭하면 팝업 메시지가 나타납니다. 레코드를 삭제하십시오.cakephp에서 jquery로 레코드를 삭제하는 방법은 무엇입니까?
https://gist.github.com/taleeb35/e61f58af9944511b1669
이 내 요점 코드입니다.
public function delete($id = null) {
if($this->request->is('ajax')) {
//$this->autoRender = false;
if ($this->User->delete($id)) {
$response = $this->Session->setFlash(__('User deleted'));
$response .= $this->redirect(array('action' => 'index'));
} else {
$response = $this->Session->setFlash(__('User was not deleted'));
$response.= $this->redirect(array('action' => 'index'));
}
return json_encode($response);
}
}
$(document).ready(function() {
$('a.delete').click(function(e) {
var __this = this;
e.preventDefault();
var parent = $(this).parent("td").parent("tr");
$.ajax({
type: 'get',
url: $(__this).attr("href"),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},3000);
},
success: function(response) {
if(response.success){
parent.slideUp(300,function() {
parent.remove();
});
}else{
alert("Failed to delete message");
parent.animate({'backgroundColor':'#fff'},1000);//Restore your background back
}
}
});
});
});
같습니다, 내가 먼저 문서를 연구 것을 강력히 제안합니다. 'setFlash()'도'redirect()'도 아무것도 반환하지 않으며,'redirect()는 물론 AJAX 요청에 반환되는 인덱스 액션 출력을 가져 오는 리디렉션을 유발합니다. – ndm