0

I have a login page which takes the user name and password and directs it to a controller. If the login information is correct, the controller sends some data to be displayed on the home page.

Now, I want to provide a link on the home page that enables the user to refresh the page on a click. This should resubmit the username and password and the page is reloaded, i.e. F5 functionality. My current code :

Please <a href='#' onclick='location.reload(true);'> refresh the page </a> 

is not exhibiting the form resubmission from the login page. How may I achieve this? Any ideas regarding this would be very helpful.

5
  • Try running window.location.href = window.location.href; Commented Jan 31, 2014 at 9:04
  • Presumably this is a POST form? What about the form inputs? Are they being populated after the initial refresh? Why do you need to submit the data again? Why can't you do whatever it is you need to do with the values the first time round? Commented Jan 31, 2014 at 9:06
  • 1
    Why do you want to repost the login form? Commented Jan 31, 2014 at 9:08
  • Yes, this is a POST form. I need to resubmit the data because the userid helps me to populate a table whose data is fetched from the database. Commented Jan 31, 2014 at 9:13
  • Don't you already have the user information in a session. If he is logged in already. Commented Jan 31, 2014 at 9:16

5 Answers 5

3

Nice cross-browser support.

To Reload the page.

window.location.replace(window.location.href);

To submit a form. Where <form id="myForm" ... >.

document.getElementById("myForm").submit();

Documentation
Replace / Href / Submit

Sign up to request clarification or add additional context in comments.

4 Comments

This does not resubmit the login form.
that depends on if the form is GET or POST
Submitting a Username and Password I think it's probably POST
I have a POST form on the login page.
0

You could do this:

Please <a href='#' onclick='document.getElementById("myForm").submit();'> refresh the page </a> 

And just having a hidden form again, if the form is not present any more.

from http://www.w3schools.com/jsref/met_form_submit.asp

Comments

0
function reloadPage()
{
location.reload();
}

call this function on click of your link

onclick="reloadPage()"

I think this works .

Comments

0

Try one of following -

window.location.reload();
history.go(0);
window.location.href=window.location.href;

Comments

0

did you try to resend the form with hidden fields?

<form id="formId" action="#">
<input type="hidden" id="user" value="#{userValue}" />
<input type="hidden" id="pass" value="#{passValue}" />
</form>

Please <a href='#' onclick='$("#formId").submit();'> refresh the page </a> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.