我需要在open模式下传递周id并在js中使用ajax将数据插入db db列是: 用户身份 week_id BOOK_NAME 作者 网页 类别 这是php代码,数据库中没有数据
@foreach($weeks as $week)
@if(Auth::user() == $week->user)
<table class="table table-bordered tar" id="week">
<span class="input-group-addon" id="basic-addon1"><i class="fa fa-table" aria-hidden="true"> <h4>{{ $week->name }}</h4></i></span>
<thead>
<tr>
<th style="background-color: #f0f0f0; color: #5d6d7e; text-align: center">الخيارات</th>
<th style="background-color: #3cb774; color: #FFFFFF; text-align: center">الإنجاز</th>
<th style="background-color: #e85657; color: #FFFFFF ; text-align: center">عدد الصفحات</th>
<th style="background-color: #ff6a06; color: #FFFFFF ; text-align: center">المجال</th>
<th style="background-color: #2c81ba; color: #FFFFFF ; text-align: center">المؤلف</th>
<th style="background-color: #0f7864; color: #FFFFFF ; text-align: center">اسم الكتاب</th>
<th style="background-color: #5d6d7e; color: #FFFFFF ; text-align: center">اليوم</th>
</tr>
</thead>
<tbody class="tbody1">
<tr data-pageid="" name="" class="tr1">
<td>
<a href="#"><i class="glyphicon glyphicon-pencil" aria-hidden="true"></i></a>
<a href="#"><i class="glyphicon glyphicon-remove" aria-hidden="true"></i></a>
</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<th scope="row"></th>
<button type="submit" data-weekid="{{ $week->id }}" id="addbook" class="btn btn-success btn-lg btn-block update_user_button">إضافة كتاب</button>
</tr>
</tbody>
</table>
@endif
@endforeach
和这个js代码并没有db
中的东西<script type="text/javascript">
var urlSave = '{{ route('add.book') }}';
var token = '{{ Session::token() }}';
var weekId = 0;
$(function () {
$('#error').hide();
$('.update_user_button').on('click', function (event) {
event.preventDefault();
var token = $('input[name="_token"]').val();
var weekId = $(this).attr('data-weekid');
var days = $('input[name="day"]').val();
var book = $('input[name="book"]').val();
var author = $('input[name="author"]').val();
var page = $('input[name="page"]').val();
var data = new FormData();
data.append('_token',token);
data.append('week_id',weekId);
data.append('book_name',book);
data.append('author',author);
data.append('page',page);
$('#edit-modal').modal();
$('#modal-save').on('click', function () {
$.ajax({
method: 'POST',
url: '{{ route('add.book') }}',
data: data,
success:function (data) {
$('#edit-modal').modal('hide');
alert('done');
},
error:function (data) {
$('#error').show();
$('#error').html('');
var error = data.responseJSON;
//$.each(error,function (k,v) {
// $('#error').append(v + '<br />');
// })
console.log(error);
}
})
});
});
});