Я пытаюсь получить значение из формы ввода, проблема в том, что я создаю эту форму ввода с помощью jQuery и Ajax, поэтому, если я проверяю, каково значение этого ввода, оно пустое.
HTML-код, который я загружаю динамически:
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Desde</label>
<input type="time" class="form-control" id="hola" aria-describedby="emailHelp" placeholder="Desde">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="exampleInputEmail1">Hasta</label>
<input type="time" class="form-control" id="until" aria-describedby="emailHelp" placeholder="Hasta">
</div>
</div>
</div>
<hr>
<button type="button" data-id="'.$i.'" class="btn btn-primary search_turn">Buscar</button>
<hr>
<h4>Turnos Disponibles</h4>
<div id="table" class="table-responsive">
<table style="width: 100%;" class="table table-bordered table-striped">
<thead>
<tr>
<th>Nombre</th>
<th>Lu</th>
<th>Ma</th>
<th>Mi</th>
<th>Ju</th>
<th>Vi</th>
<th>Sa</th>
<th>Do</th>
<th>Horas</th>
</tr>
</thead>
<tbody class="turns">
</tbody>
</table>
</div>
</div>
<div class="modal-footer">
<input type="hidden" id="year" value="">
<input type="hidden" id="month" value="">
<input type="hidden" id="id_week" value="'.$i.'">
<input type="hidden" id="id_branch_office" name="id_branch_office" value="'.$id_branch_office.'">
<button type="button" class="btn btn-primary">Continuar</button>
</div>"'
Этот HTML-код выше я добавил к этому модальному динамически:
<!-- Modal -->
<div class="modal fade bd-example-modal-xl" id="myModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Seleccionar Turno - Semana</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
Когда я нажимаю кнопку Buscar из первого HTML-кода, ввод долженпримите значение, которое я поставил, но оно пустое.
Мой код Ajax:
$( 'body' ).on( "click", '.search_turn', function() {
var $('#edit-auction-modal ').find('input#input-id')
var id = $(this).attr('data-id');;
var since = $('#since').val();
var until = $('#until').val();
var id_week = $('#id_week').val();
var id_branch_office = $('#id_branch_office').val();
if(since != '' && until != '')
{
alert(5);
$.ajax({
type:'POST',
url:"{{ url('/turn/search') }}",
data: {
_token: "{{csrf_token()}}", since: since, until: until, id_branch_office: id_branch_office, id_week: id_week
},
success:function(result)
{
$(".turns").html('');
$(".turns").html(result);
}
});
}
});
Если я проверяю, поскольку переменная пуста, почему?