Refresh Certain Element Every Few Minutes

Hi,

Is there a piece of code i can use to refresh my blog feed so #blogfeed1 every 5 minutes or so? It’s a live blog page im running and need this to refresh the element only and not the full site?

Hi,

is the blog a Wix Blog application or your own blog built with Wix Code?

If it is your own blog built with Wix Code, you can refresh the dataset every 5 minutes by setting a function to repeat every 5 minutes using setInterval :

setInterval(() => $w('#dataset1').refresh(), 300000)

If it is Wix Bog application, then there currently is no way to refresh just the contents of it.

2 Likes

Can you use setInterval on functions in backend code folder? To make code go and fetch new data every 5 minute?

No, you cannot use SetInterval in backend code.
or rather, you could, but there’s no guarantee that these will repeat for any specified length of time.
instead, you can use setInterval from the browser and invoke a call to a backend function.

somewhere in our backlog we’ll implement backend jobs - the ability to have logic execute every X minutes regardless of any browser logic.

2 Likes

Ok, these kind of WIX Cron will be most welcome in the future.

2 Likes

Is there anyway to force the HTML component to refresh content, I am setting the URL on interval but the content does not change.

Andreas, I´m pretty sure you already checked, but just to make sure: have you tried a combination of window.setTimeout() and location.reload() inside the html-component? It might wotk.

1 Like

Hi,

I tried Giedrius’s bit of code on my dynamic page and also added a console log, and it doesn’t seem to refresh every X seconds, it just returns one confirmation message and that’s it.

Here’s my code :

import wixData from 'wix-data';


$w.onReady(function () {
	$w("#dynamicDataset").onReady( () => {
		$w("#repeater2").onItemReady( ($w) => {
	
		//strikes through 'previous price'
  		$w("#text63").html = `<span style="font-family:arial; color:#C0C0C0; text-decoration: line-through;font-size:17px">${$w("#text63").text}</span>`;
  	
  		//modifies the time and date
		const originalDate = $w("#text62").text;
		const newDate = originalDate.split(' ').splice(1, 4).join(' ');
			$w('#text62').text = newDate;
		 	console.log('Time removed from Date/Time Stamp: New Date ' + newDate);
		});
	

	});
	//(not working) auto refresh the database every 15 seconds
	setInterval(() => $w('#dynamicDataset').refresh(), 15000);
		console.log('Done refreshing Dataset');
});

Any help?

bump

Hi Tristan,
The refresh does work but the console.log is is not in the scope of the setinterval so it doesn’t print it.

setInterval(() => {
	$w('#dataset1').refresh();
	console.log('Done refreshing Dataset');
}, 15000);

Roi

Thanks Roi it works !

It doesn’t work for me. I don’t use the dataset for a blog, but for a store. It just doesn’t refresh…

Hi, I used set interval to refresh data set every second, but it’s refreshing my text box user input text as well…
How can I prevent the user text from erasing every second??