0
I have an ajax search that picks up some data based on what was searched, how do I play this 'date' coming from an ajax in a foreach in php ?
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type: 'get',
url: '{{route('
videos.index ')}}',
data: {
search: $valor
},
// contentType: "application/json; charset=utf-8",
datatype: "text",
beforeSend: function() {
$("#resultado").html("Carregando...");
// document.getElementById('paginate').style.display = 'none';
},
success: function(data) {
if ($.trim(data)) {
console.log(data);
$('#resultado').append(data);
$('#last_videos').html(" ");
document.getElementById('create_video').style.display = 'none';
document.getElementById('paginate_total').style.display = 'none';
document.getElementById('paginate_ajax').style.display = 'block';
} else {
$('#resultado').html("Video não encontrado no banco de dados ou URL invalida");
$('#last_videos').html(" ");
// document.getElementById('create_wistia').style.display = 'block';
}
},
error: function(data) {
$('#last_videos').html(" ");
$('#resultado').html("Erro ao pesquisar...");
}
});
I want to take the result of Success ajax and play in this foreach
<div id ="last_videos">
@foreach($data as $video)
<div class="sc-box " id="{{ $video->id }}">
<div class="row">
<div class="col-md-12 text-left">
<span class="sc-code"><big>{{ $video->code_video }}</big></span>
<a href="javascript:void(0);" class="cinza"><span class="fa fa-lock"></span></a>
(<span class="fa fa-clock-o"></span> {{ $video->duration }})
<a href="{{ route('videos.edit', $video->id) }}" class="fa fa-edit"></a><br />
<b>{{ $video->title }}</b>
<br /><br />
</div>
</div>
<div class="row">
<a href="{{ route('videos.edit', $video->id) }}">
@if ($video->image)
<img style='width: 200px; height: 250px' src="{{ URL::to('/uploads/' . $video->image) }}" class="sc-class-gallery img-responsive">
@elseif ($video->thumbnail)
<img style='width: 200px; height: 250px' src="{{ $video->thumbnail }}" class="sc-class-gallery img-responsive">
@endif
</a>
</div>
</div>
@endforeach
@else
<img src="{{ URL::asset('images/no-video.png') }}" width="250">
<h3>{{ trans('field.video_index') }}</h3>
<p>{!! trans('field.text_video_index') !!}</p>
@endif
</div>
Post your code, help in solving the problem.
– Mateus Veloso
"in a foreach in php" - you mean in Javascript or PHP?
– Sergio
I put the code to better illustrate.
– Wendel Freitas
Ajax is javascript, so the reply to the request will have to be treated with javascript and not PHP. You can eventually send the reply in a new request you have in the PHP server-side.
– Filipe Moraes