I using bootboxjs as modal dialog. This is my example
HTML
<a href="javascript:();" data-id="1" class="delete-post">Delete</a>
Javascript
$('delete-post').click(function(){
var id_value = $('#elemtent').attr('data-id'); // get value post you want delete
bootbox.dialog({
title: 'Confirm',
message: 'Are you sure delete this post',
className: 'my-class',
buttons: {
cancel:{
className: 'btn btn-default',
label: 'Close'
},
success: {
className: 'btn btn-success',
label: 'Delete',
callback: function(){
$ajax({
data: {id: id_value},
dataType: 'json',
type: 'post',
urL: 'http://localhost/post/delete',
success: function(response){
if(response.status == 'success'){
// Your action after delete
}
else {
$(this).dialog('open');
}
}
});
}
}
}
});
});
Router
Route::any('post/delete','PostController@delete_post');
Controller
..................
function delete_post(){
$id =$_REQUEST['id'];
// YOUR ACTION
if($this->post->delete($id)){
return array('status'=>'success');
}
else {
return array('status'=>'error');
}
}
...................
ottz0 said:
Hi Thanks for this. I'm presuming the data-id="1" would be data-id="{{id}}" for blade that gets passed? Example view
@foreach($posts as $post)
<li><a href="javascript:();" data-id="{{$post->id}}" class="delete-post">Delete</a></li>
@endforeach
Thanks.
The url: is the same page itself to get the id?
the // Your action after delete..... would be a confirmation page? this data has now been deleted?
ottz0 said:
Thanks.
The url: is the same page itself to get the id?
the // Your action after delete..... would be a confirmation page? this data has now been deleted?
Yes, it's
url is link call route delete post.
I don't understand your question. Can you post full code or image, may be i help you
Thanks I used the reference $this and it worked... Thanks
I can't seem to send it as post, only as get sending it through the URL.
I can't pick the variable up on my controller using $id =$_REQUEST['id'] or $id =$_POST['id'];
Any Ideas?
$.ajax({ data: {id: id_value}, dataType: 'html', type: 'get', url: 'http://localhost:8000', complete: function(jqXHR, data) { if(jqXHR.readyState === 4) {
window.location.href='http://localhost:8000/test_delete/cityId/'+id_value;
}
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community