Forced refresh

Hello.

Here is my problem (Go to my site to understand):

When I click on my “Genre précédent” or “Genre suivant” buttons to go to the previous or next page, my wallpaper does not change. (It is linked to the genre database). I have to refresh my page manually to display the right background…

What code should I use so that when I click on the icon of the next or previous page, it automatically refreshes the page and displays the right background?

Thanks for your help

Ou est ton CODE?
Tu pas utilise → CODE?

Where is your current working (not working code) ?

No code, for the moment… It’s just dynamic pages

Dynamic pages connected with DATASET, right?

When you are talking about → dynamic-pages ← do you know the difference between a dynamic page and a normal page?

Already have taken a look onto…
https://www.wix.com/velo/reference/wix-dataset/dataset/getcurrentitem

You want to create a button controled previous/next-functionality for …

…where you want to be able to change the background with every change done by the two shown vector-buttons (or what ever these buttons are).

https://www.wix.com/velo/reference/wix-dataset/dataset/previous
https://www.wix.com/velo/reference/wix-dataset/dataset/next

$w.onReady(()=>{
  $w.('#myDatasetIDhere).onItemReady(()=>{console.log("My Dataset is ready!");
      $w('#myPreviousButtonIDhere').onClick(()=>{console.log("Previous-Button clicked!")
	
      });
   
      $w('#myNextButtonIDhere').onClick(()=>{console.log("Previous-Button clicked!")
	
      });
   });
});

Complete the code!

A dynamic page depends on a database. My wallpapers for these pages depend on this database. One background per page.

When it’s a normal page, like my home page and the two following ones, the backgrounds are specific to these pages, without any link behind.

I will test the codes. Thanks for the answer.

In short: On a dynamic-page → every element is/can be connected directly to a database. And always JUST ONE ITEM can be loaded at ONCE.

My provided code is of course not complete. It is just an example to give you some little hints and pull you into right direction.

it doesn’t work… I am not the king of code… :stuck_out_tongue:

There was also an prepared BUG in my provided code to test you, if you do use console! You didn’t! Didn’t you? Did you take a look onto → CONSOLE?

Do you know what the → CONSOLE ← is and how it looks like?

If not → you will find the CONSOLE in the PREVIEW-MODE of your Wix-Editor on the very bottom (expand the bottom property-window).

Or if you use GOOGLE-CHROME or the EDGE-Browser → press F12 and navigate to console.

Investigate the output-results.

Do you get some → ERRORS? Of course you get!!! Why?

Because there is an ISSUE in your (my :wink:) CODE-SYNTAX. I will mark it for you!
Delete the marked CHARACTER in the shown code below.
Save or publish your site again and do a second try. What do you get in CONSOLE?

$w.onReady(()=>{
  $w.('#myDatasetIDhere).onItemReady(()=>{console.log("My Dataset is ready!");
      $w('#myPreviousButtonIDhere').onClick(()=>{console.log("Previous-Button clicked!")
    
      });
   
      $w('#myNextButtonIDhere').onClick(()=>{console.log("Previous-Button clicked!")
    
      });
   });
});

Still getting some ERRORS?
Check if you also have replaced the element-IDs with your own ones…
I will mark the related code-parts for you…

$w.onReady(()=>{console.log("My page is ready!");
  $w.('#myDatasetIDhere).onItemReady(()=>{console.log("My Dataset is ready!");
      $w('#myPreviousButtonIDhere').onClick(()=>{console.log("Previous-Button clicked!")
    
      });
   
      $w('#myNextButtonIDhere').onClick(()=>{console.log("Previous-Button clicked!")
    
      });
   });
});

Now read this…

Expand your code to get the → “Current-Item” → Console-log it! Take a look onto console again and check for RESULTS. Were you able to get some data?

Do I replace the ’ with " in your code ?

I have this error on line 2 : TypeError: $w(…).onItemReady is not a function

Ok, this was a second test on you :joy:.
You have still an SYNTAX-ERROR in this code-line…
$w . ( '#myDatasetIDhere) . onItemReady (() => { console . log ( “My Dataset is ready!” );

Compare these 3 code-lines…

$w('#myDatasetIDhere)
$w('#myNextButtonIDhere')
$w('#myNextButtonIDhere')

…find the → bug/error

BTW: You can use either → " " ----> or —> ’ ', but do not mix them!

$w . onReady (()=>{ console . log ( “My page is ready!” );
$w ( “#dynamicDataset” ). onItemReady (()=>{ console . log ( “My Dataset is ready!” );
$w ( “#vectorImage3” ). onClick (()=>{ console . log ( “Previous-Button clicked!” )

  }); 

  $w ( "#vectorImage2" ). onClick (()=>{ console . log ( "Previous-Button clicked!" ) 

  }); 

});
});

On the “.onItemReady”, i have this message : Property ‘onItemReady’ does not exist on type ‘dynamicDataset’.

Sorry, this one is MY FAULT :grin:. (oooops, this mistake happened to me totaly by chance :grin::grin::grin::grin::grin::grin:)

But, now you should be able also to fix this last ERROR by your own.
Did you read this one ???

https://www.wix.com/velo/reference/wix-dataset/dataset/getcurrentitem

Please read it again!

My english is limited :stuck_out_tongue: I’m french ^^

Seulement pour toi/vouz en francais encore-un-fois.

Désolé, celui-ci est MA FAUTE (hopla! cette erreur m’est arrivée totalement par coïncidence ).

Mais, maintenant, vous devriez pouvoir corriger cette dernière ERREUR par vous-même.

Avez-vous lu celui-ci ???

https://www.wix.com/velo/reference/wix-dataset/dataset/getcurrentitem

Veuillez le relire !

I must be stupid or blind, but I don’t see where the mistake is

I still do see 2x MISSTAKES!

$w.onReady(()=>{console.log("My page is ready!");
  $w("#dynamicDataset").onReady(()=>{console.log("My Dataset is ready!");
      $w("#vectorImage3").onClick(()=>{console.log("Previous-Button clicked!")
   
      });
   
      $w("#vectorImage2").onClick(()=>{console.log("Next-Button clicked!")
    
      });
   });
});

Et s’il te plait utilise → CODE-BLOCKs, par pour montrer ton/votre code.

I have no more errors in the code, but it doesn’t work. It still doesn’t change my backgrounds when I go to the next dynamic page… I always have to do an F5 to refresh my page and see the right background appear…

Je sais. :grin:

Your code is now 50% - complete.
Still 50% remaining and has to be coded!

https://www.wix.com/velo/forum/coding-with-velo/change-background-image

It doesn’t help me anymore…

thanks for the help though