I've made a page that logs on, and logs off with forms, php, and javascript.

But the only problem is when you submit the form and the data changes it doesn't update until the page reloads.

<form method='POST' id='login' onsubmit='location.reload();'>
    <input placeholder='Username' type='text' name='user' value='" . $_POST['user'] . "' />
    <input placeholder='Password' type='text' name='pass' value='" . $_POST['pass'] . "' />
    <input type='submit' value='Login' />
</form> 

Notice how the location.reload() is in, but it still doesn't work.

Would there be any possible way to fix this with only JavaScript?

有帮助吗?

解决方案

What you want to do is submit the form data asyncronously in the background. JQuery makes this easy... look at this answer, it should get you on the right track.

PHP + Ajax Login

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top