Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel & Bootstrap ajax modal example
// html
<div>This is my post</div>
<!-- Just put this div at the bottom of your template somewhere-->
<!-- Notice that its hidden by default, so if it doesnt get used, thats fine-->
<div class="modal hide"></div>
//JS
$.ajax({
type: 'post', // or post?
dataType: 'json',
url: SITE_BASE + uri, // change as needed
data: requestData, // if you are posting
success: function(data) {
if (data.success) {
// notice that we are expecting a json array with success = true and a payload
$('.modal').empty().append(data.payload).modal();
} else {
// for debugging
alert(data);
}
},
error: function(xhr, textStatus, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
//php
return Response::json(array('success' => true, 'payload' => View::make('posts.item'))
@sogeniusio

This comment has been minimized.

Copy link

commented Apr 26, 2017

This looks like what I need. I'm definitely going to try this out. Thanks :-)

@madurapa

This comment has been minimized.

Copy link

commented Feb 25, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.