I Need to display the four advertisement banner in my website based on the ad type. The Database table have id, img_name, duration, type, date_to_display.
# for DB TABLE COLUMN
> I Want to fetch all data where #date_to_display contain as today date
> then I show the images in Img tag, that image show only DB contain #duration time
> then the time is end next picture is shown which is same #type
> the #type COLUMN have four categories
> show i need four image Tags
> the Image tags are regularly changed the based on #duration
i completed with javascript.
> Ajax get the datas from the Laravel it Return the data as a JSON Format
> Ajax Response data will be Divide & store to new four Array varaibles based On The #type
> Then Create a varaible and declare the SetTimeout Function and this function called itself recursively
> Settimeout Function Every One Second Execute the Callback Function
> then the ad will be display as a particular time
Its My Code
function loadImages() {
$.ajax({
type : "GET",
url : "/ad/ask",//laravel Route URL
success:function(rdata){
/************Its My Response data(rdata)***************** (13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}] 0: {id: 6, img_name: "1565004555.jpg", img_type: "A", duration: "3", show_date: "2019-08-06", …} 1: {id: 7, img_name: "1565006659.jpg", img_type: "A", duration: "3", show_date: "2019-08-06", …} 2: {id: 10, img_name: "1565011307.jpg", img_type: "A", duration: "2", show_date: "2019-08-06", …} 3: {id: 14, img_name: "1565011368.jpg", img_type: "B", duration: "3", show_date: "2019-08-06", …} 4: {id: 5, img_name: "1565004536.jpg", img_type: "B", duration: "1", show_date: "2019-08-06", …} 5: {id: 11, img_name: "1565011333.jpg", img_type: "B", duration: "1", show_date: "2019-08-06", …} 6: {id: 3, img_name: "1565002220.jpg", img_type: "C", duration: "2", show_date: "2019-08-06", …} 7: {id: 12, img_name: "1565011342.jpg", img_type: "C", duration: "2", show_date: "2019-08-06", …} 8: {id: 9, img_name: "1565011295.jpg", img_type: "C", duration: "4", show_date: "2019-08-06", …} 9: {id: 4, img_name: "1565004520.jpg", img_type: "C", duration: "2", show_date: "2019-08-06", …} 10: {id: 15, img_name: "1565011383.jpg", img_type: "C", duration: "2", show_date: "2019-08-06", …} 11: {id: 8, img_name: "1565006674.jpg", img_type: "D", duration: "1", show_date: "2019-08-06", …} 12: {id: 13, img_name: "1565011354.jpg", img_type: "D", duration: "2", show_date: "2019-08-06", …} */ var ty1=[],ty2=[],ty3=[],ty4=[]; var asset=JSON.stringify(rdata); orgData=JSON.parse(asset); for(i=0;i
if(i2==(ty2.length-1) && wt2==ty2[i2])
{
i2=0;
$('#type2').attr('src',"images/"+ty2[i2]);
i2=1;
wt2=1;
}else{
if(wt2==ty2[i2])//i=1;wt=1;ty[i]=3
{
i2+=1;
$('#type2').attr('src',"images/"+ty2[i2]);
i2+=1;
wt2=1;
}else{
wt2+=1;
}
}
if(i3==(ty3.length-1) && wt3==ty3[i3])
{
i3=0;
$('#type3a').attr('src',"images/"+ty3[i3]);
$('#type3b').attr('src',"images/"+ty3[i3]);
i3=1;
wt3=1;
}else{
if(wt3==ty3[i3])//i=1;wt=1;ty[i]=3
{
i3+=1;
$('#type3a').attr('src',"images/"+ty3[i3]);
$('#type3b').attr('src',"images/"+ty3[i3]);
i3+=1;
wt3=1;
}else{
wt3+=1;
}
}
if(i4==(ty4.length-1) && wt4==ty4[i4])
{
i4=0;
$('#type4').attr('src',"images/"+ty4[i4]);
i4=1;
wt4=1;
}else{
if(wt4==ty4[i4])
{
i4+=1;
$('#type4').attr('src',"images/"+ty4[i4]);
i4+=1;
wt4=1;
}else{
wt4+=1;
}
}
setTimeout(myTimer, 5000);
}, 5000);
setTimeout(() => {
console.log('After 5 Minutes Timeout Will Cleared');
clearTimeout(timer);
}, 1000*60*5);
}
});
}
I'm Used Laravel 5.5 Solution Will Be In PHP is Better
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire