问题
If i click the "change" button in de modal, they will close and nothing is updated in my database.
First of all, the data should be updated in the database and after that i want to show the user that the data is saved. Then the user can press the 'close' button on the modal of click anywhere to close the modal outside the modal frame.
This is my link for opening the modal:
<a href="#" data-id="1" class="btn btn-primary showme">Show Me</a>
This is my Jquery ajax script:
<script type="text/javascript">
jQuery(function($){
$('a.showme').click(function(ev){
ev.preventDefault();
var uid = $(this).data('id');
var uid2 = $(this).data('id2');
$.get('test-modal.php?id=' + uid + '&id2=' + uid2, function(html){
$('#modal-7 .modal-body').html(html);
$('#modal-7').modal('show', {backdrop: 'static'});
});
});
});
</script>
This is my code for the modal:
<div class="modal fade" id="modal-7">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Dynamic Content</h4>
</div>
<div class="modal-body">
Content is loading...
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
The code of test-modal.php:
<?php
$id = $_GET['id'];
$id2 = $_GET['id2'];
require ('config.php');
$conn = mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($dbnm) or die (mysql_error());
$sql = "SELECT * FROM historiek WHERE id = '". $id ."'";
$res = mysql_query($sql) or die (mysql_error());
while($row = mysql_fetch_assoc($res)) {
?>
<div class="row">
<form role="form" method="post">
<div class="form-group">
<textarea class="form-control ckeditor" id="editor10" name="historiek" rows="10"><?php echo $row['historiek']; ?></textarea>
</div>
<div class="form-group">
<button type="submit" name="Submit" class="btn btn-info">Change</button>
</div>
</form>
</div>
<?php
if (isset($_POST['Submit'])) {
$id = $_GET['id'];
$historiek = $_POST['historiek'];
require ('config.php');
$conn = mysql_connect($host,$user,$pass) or die (mysql_error());
mysql_select_db($dbnm) or die (mysql_error());
$sql = "UPDATE historiek SET historiek = '$historiek' WHERE id = '". $id ."'";
$res = mysql_query($sql) or die (mysql_error());
}
?>
Can anyone help me out here?
来源:https://stackoverflow.com/questions/26641086/save-button-inside-bootstrap-modal-3