Created
October 9, 2012 16:03
-
-
Save niallobrien/3859740 to your computer and use it in GitHub Desktop.
Laravel & Bootstrap ajax modal example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
This looks like what I need. I'm definitely going to try this out. Thanks :-)