Last active
August 29, 2015 14:04
-
-
Save lordspace/d950dfbd81b4a7f7213a to your computer and use it in GitHub Desktop.
Example: How to Make an Ajax Request when Twitter Bootstrap Alert is Dismissed. More info on: http://slavi.ca/tutorials/make-ajax-request-twitter-bootstrap-alert-dismissed/
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
<?php | |
echo 'Ok'; | |
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<title>Example: How to Make an Ajax Request when Twitter Bootstrap Alert is Dismissed</title> | |
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> | |
<!-- WARNING: Respond.js doesn't work if you view the page via file:// --> | |
<!--[if lt IE 9]> | |
<script src="//oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> | |
<script src="//oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> | |
<![endif]--> | |
<!-- Latest compiled and minified CSS --> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" /> | |
<!-- Optional theme --> | |
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css" /> | |
</head> | |
<body> | |
<div class="row"> | |
<div class="col-md-6"> | |
<h1>Hello, world!</h1> | |
<div> | |
This example code shows you how you can call JavaScript (ajax) when an alert is dismissed so you | |
can make sure the message doesn't bug the user again. | |
</div> | |
<div> | |
Here is a link to the <a href='http://slavi.ca/tutorials/make-ajax-request-twitter-bootstrap-alert-dismissed/' target='_blank'>blog post</a> | |
</div> | |
<br/> | |
<div class="alert alert-warning alert-dismissible" role="alert" data-id="100" data-user_id="500"> | |
<button type="button" class="close" data-dismiss="alert"> | |
<span aria-hidden="true">×</span><span class="__sr-only">Close</span> | |
</button> | |
<strong>Warning!</strong> Start coding, you're missing the fun! | |
</div> | |
</div> | |
</div> | |
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) --> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> | |
<!-- Latest compiled and minified JavaScript --> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> | |
<script> | |
$(document).ready(function($) { | |
// This handles when the user clicks on an X button of an alert message. | |
// We need to call ajax to make sure the message is deleted so it doesn't bug the user again. | |
$('.alert-dismissible').bind('closed.bs.alert', function () { | |
var id = $(this).data('id') || 0; | |
var user_id = $(this).data('user_id') || 0; | |
$.get('ajax.php?cmd=dismiss_alert&user_id=' + escape(user_id) + '&id=' + escape(id)); | |
}); | |
}); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment