Reload page after button click

After users click the button to submit their form i would like the page to reload.
I use this code, page name is “Test”, but something isn’t working - it is not reloading.
Any help is appreciated thank you.

import wixLocation from ‘wix-location’;
export function button1_click(event, $w) {
$w(‘#dataset1’).setFieldValue(‘username’,$w(‘#input1’).value);
$w(‘#dataset1’).save();
wixLocation.to(“/test”);
}

In order to reload the page, you need to use the full url:

wixLoaction.to("https://www.mydaomain.com/test");

also, since .save() is a promise, you should wrap the reloading inside .then() , otherwise it might reloads before the save action completed.

@jonatandor35 Thank you my code now works. Can you elaborate further on the .then() The only problem i have now is that the page reloads so fast that the user can not see the success or failure message linked to the button. Is there a way i can slow down the code by a couple seconds?

import wixLocation from ‘wix-location’;
export function button1_click(event, $w) {
$w(‘#dataset1’).setFieldValue(‘username’,$w(‘#input1’).value);
$w(‘#dataset1’).save();
wixLocation.to(“https://dcaffery900.wixsite.com/mysite-1/blank”).then();
}

@dcaffery900

//code....
    $w('#dataset1').save()
then(() => {
    wixLocation.to("https://dcaffery900.wixsite.com/mysite-1/blank")
}
}

and if you want to wait with the refreshing, you’ll need to add setTimout() method.
But why do you refresh the page and not only the dataset?

I would like to refresh my page/website after this code :

$w . onReady (() => {
$w ( “#logoutButton” ). onClick ( logoutAndRedirect );
});

function logoutAndRedirect ( event ) {
Promise . all ( [ wixLocation . to ( “https://onlinesanawad.editorx.io/business” ), wixUsers . logout () ] );
}

//---------------------------------------------------------
Kindly help me. Thanks in advance : )