Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save notridan/c3a8a0e1817afdc47e179c7efa7fdc1c to your computer and use it in GitHub Desktop.
Save notridan/c3a8a0e1817afdc47e179c7efa7fdc1c 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'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment