I have a project which I can add multiple data. ex: I will add 2 names and it will be display on the next table. Also I converted each data into json so that I can pass it to the controller. Now my problem is that every time I click the check button the controller can only read the last data I inputted. Is there any way to get all data from table and pass it to controller? Here's my script.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
$("#submit-button").click(function(){
var data = $('#form_id').serializeArray();
var obj = {};
for (var i = 0, l = data.length; i < l; i++) {
obj[data[i].name] = data[i].value;
}
var json_text = JSON.stringify(obj);
$('#submit-button').after('<pre>' + json_text + '</pre>'); //shows only to determine if its working.
$('table.footable tbody').append('<tr><td><input type="hidden" name="request" value='+json_text+'></td> <td>'+obj['firstname']+'</td><td>'+obj['lastname']+'</td></tr>');
$("#firstname").val('');
$("#lastname").val('');
})
})
</script>
<form id="form_id">
<label for="firstname">First Name:</label>
<input type="text" id="firstname" name="firstname" value="" placeholder="Max" required="required" autofocus="autofocus" />
<label for="lastname">Last Name:</label>
<input type="text" id="lastname" name="lastname" value="" placeholder="Max" required="required" autofocus="autofocus" />
<input type="button" value="submit" id="submit-button" />
</form>
<div id="table">
<h2>List of all person</h2>
<form method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<table class="footable">
<thead>
<tr>
<th data-class="expand"> First Name </th>
<th> Last Name </th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<button class="btn btn-lg btn-primary btn-sm">Check</button>
</form>
</div>
</body>
</html>
laravel php laravel 5 laravel 4 laravel with laravel tutorial
Aucun commentaire:
Enregistrer un commentaire