Skip to content

Instantly share code, notes, and snippets.

@niallobrien
Created October 9, 2012 16:03
Show Gist options
  • Save niallobrien/3859740 to your computer and use it in GitHub Desktop.
Save niallobrien/3859740 to your computer and use it in GitHub Desktop.
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'))
@hosquiat
Copy link

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

@madurapa
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment