Support the ongoing development of Laravel.io →
Views Blade Forms
Last updated 1 year ago.
0

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');
	}
}
...................
Last updated 1 year ago.
0

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
Last updated 1 year ago.
0

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?

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

I don't understand your question. Can you post full code or image, may be i help you

Last updated 1 year ago.
0

Thanks I used the reference $this and it worked... Thanks

Last updated 1 year ago.
0

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;
					
					   }   
					}   
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ottz0 ottz0 Joined 15 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.