Reputation: 25
I'am trying to get multiple images from variable have multiple images but i only get one.
the variable is $src.
// the frontend code
foreach ( $chapter['storage'][ $in_use ]['page'] as $page => $link ) {
$host = $chapter['storage'][ $in_use ]['host'];
$src = $host . $link['src'];
}
$this->send_json( 'success', '', $src );
// ajax code
$(function(){
$('.entry-content .entry-content_wrap').ready(function(){
var navigation = $('.single-chapter-select').find('option:selected').data('navigation');
$.ajax({
type: 'GET',
url: manga.ajax_url + '?' + navigation,
dataType: 'json',
success: function(data){
var imag_link = data.data.data;
console.log(imag_link);
$('.entry-content .entry-content_wrap').html('<img style="margin: -6px;width: 89%;pointer-events: none;" class="wp-manga-chapter-img" src="' + imag_link + '">');
},
})
})
})
Upvotes: 1
Views: 43
Reputation: 1349
In your PHP code you need to collect all of the URLs in an array and return it.
$sources = [];
foreach ( $chapter['storage'][ $in_use ]['page'] as $page => $link ) {
$host = $chapter['storage'][ $in_use ]['host'];
$src = $host . $link['src'];
$sources[] = $src;
}
$this->send_json( 'success', '', $sources );
In frontend you should loop over the sources and attach them to your html as you wish.
Upvotes: 1