I have created a form based on JSON feed, when the user click on “Save”, I have bootstrap modal window showing up and form doesnt get submitted
But I noticed when I add this piece of code, the form is getting submitted, I need this to populated the modal window and display a table in the modal window.
How can i prevent it from submitting?
Modified code:
$('#myModal').modal('show');
$.each(data, function(key, val) {
var tablefeed= $('<tr><td>ID: '+key+'</td><td id="'+key+'">'+val+'</td><tr>').appendTo('#display');
});
$(".modal-body").html(tablefeed);
I moved to ev.preventdefault as the @pmandell had suggested and that worked
<script type="text/javascript">
$('#myform').on('submit', function(ev) {
ev.preventDefault();
var data = $(this).serializeObject();
json_data = JSON.stringify(data);
$("#results").text(json_data);
$('#myModal').modal('show');
$.each(data, function(key, val) {
var tablefeed= $('<tr><td>ID: '+key+'</td><td id="'+key+'">'+val+'</td><tr>').appendTo('#display');
});
$(".modal-body").html(tablefeed);
});
});
1 Answer