get title from JSON

I am stuck!..
I have a jQuery script where i am populating a gallery of images from a JSON file, its like a lightbox type of thing.
But i want to have a title to my images, so i have created a second JSON file where i just keep, image name, and title.
I want to, in the loop, check the second JSON if the image name is there, and if it is, return the text that is the title…

This is the titles.json

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>[
{"Img" : "fun1_001.jpg", "title" : "Title of image 001"},
{"Img" : "fun1_002.jpg", "title" : "title of image 002"},
{"Img" : "fun1_003.jpg", "title" : "title of image 002"}
]
</code>
<code>[ {"Img" : "fun1_001.jpg", "title" : "Title of image 001"}, {"Img" : "fun1_002.jpg", "title" : "title of image 002"}, {"Img" : "fun1_003.jpg", "title" : "title of image 002"} ] </code>
[
    {"Img" : "fun1_001.jpg", "title" : "Title of image 001"},
    {"Img" : "fun1_002.jpg", "title" : "title of image 002"},
    {"Img" : "fun1_003.jpg", "title" : "title of image 002"}
]

What i want to do is to loop through all images, populate the gallery, and in the same time IF the image name is present in the titles.json, put that title in the loop.

This is the jQuery that populates the gallery. it calls a function named GetTitle(imagename,folder)

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> //Load the gallery if you click the dropdown.
$(document).on('click','#zmenu>div.item', function(){
$('#dc_preload_image').empty();
let zGallery=$(this).attr('data-value');
$.getJSON('JSON/Gallerys/'+zGallery+'.json', { get_param: 'value' }, (data)=>{
$.each(data, function(index, element) {
console.log('anrop')
$('.galpop-info').galpop();
$("#dc_preload_image").preloader();
$('#dc_preload_image').append('<li><a class="galpop-info" data-galpop-group="info" title="'+GetTitle(element.imageName, zGallery)+'" href="BKND/Galleries/'+zGallery+'/pict/'+element.imageName+'"><img src="BKND/Galleries/'+zGallery+'/tmb/'+element.imageName+'" alt="'+element.imageName+'" id="'+element.imageName+'" class="corners" /></a></li>');
});
});
});
</code>
<code> //Load the gallery if you click the dropdown. $(document).on('click','#zmenu>div.item', function(){ $('#dc_preload_image').empty(); let zGallery=$(this).attr('data-value'); $.getJSON('JSON/Gallerys/'+zGallery+'.json', { get_param: 'value' }, (data)=>{ $.each(data, function(index, element) { console.log('anrop') $('.galpop-info').galpop(); $("#dc_preload_image").preloader(); $('#dc_preload_image').append('<li><a class="galpop-info" data-galpop-group="info" title="'+GetTitle(element.imageName, zGallery)+'" href="BKND/Galleries/'+zGallery+'/pict/'+element.imageName+'"><img src="BKND/Galleries/'+zGallery+'/tmb/'+element.imageName+'" alt="'+element.imageName+'" id="'+element.imageName+'" class="corners" /></a></li>'); }); }); }); </code>
   //Load the gallery if you click the dropdown.
        $(document).on('click','#zmenu>div.item', function(){
            $('#dc_preload_image').empty();
            let zGallery=$(this).attr('data-value');
            $.getJSON('JSON/Gallerys/'+zGallery+'.json', { get_param: 'value' }, (data)=>{ 
                $.each(data, function(index, element) {
                console.log('anrop')
                    $('.galpop-info').galpop();
                    $("#dc_preload_image").preloader();    
                    $('#dc_preload_image').append('<li><a class="galpop-info" data-galpop-group="info"  title="'+GetTitle(element.imageName, zGallery)+'" href="BKND/Galleries/'+zGallery+'/pict/'+element.imageName+'"><img src="BKND/Galleries/'+zGallery+'/tmb/'+element.imageName+'" alt="'+element.imageName+'" id="'+element.imageName+'" class="corners" /></a></li>');
                });
            });
        });

This is the function that should match the image name from the loop and return the title.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>function GetTitle(a,z){
$.getJSON('BKND/Galleries/'+z+'/titles.json', (adata) => {
// Handle the JSON data here
let zTitle
$.grep(adata, function(value) {
if(value.Img = a){
zTitle = value.title;
}
else{zTitle = " ";}
});
console.log(zTitle)
return zTitle
});
}
</code>
<code>function GetTitle(a,z){ $.getJSON('BKND/Galleries/'+z+'/titles.json', (adata) => { // Handle the JSON data here let zTitle $.grep(adata, function(value) { if(value.Img = a){ zTitle = value.title; } else{zTitle = " ";} }); console.log(zTitle) return zTitle }); } </code>
function GetTitle(a,z){
    $.getJSON('BKND/Galleries/'+z+'/titles.json', (adata) => {
        // Handle the JSON data here  
        let zTitle         
    $.grep(adata, function(value) {
        if(value.Img = a){
            zTitle = value.title;
        }
        else{zTitle = " ";}
    });
    console.log(zTitle)
    return zTitle
});
}

No matter how i try, i cant get it right. i almost solved when i put the code inside function in the loop, but then it iterated through it and created doubles of images in the gallery instead.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật