Note that there are some explanatory texts on larger screens.

plurals
  1. POSubmit button refreshes the page even when .submit() returns false
    primarykey
    data
    text
    <p>I am making a forum that does not require page refreshing. It is coming along swimmingly, except for the fact that on a failed login attempt, the page reloads.</p> <p>I've done all the googling, and found that my jQuery "return false" on the .submit event should prevent the reload, but it doesn't! Here is the code:</p> <p>HTML:</p> <pre><code>&lt;div id='sidebar'&gt; &lt;p&gt;Login&lt;/p&gt; &lt;form id='login'&gt; &lt;input class='logininfotext' type='text' id='login_username' placeholder='username'/&gt; &lt;/br&gt; &lt;input class='logininfotext' type='password' id='login_password' placeholder='password'/&gt; &lt;/br&gt; &lt;input name='loginbutton' type='submit' value='login'/&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>CSS:</p> <pre><code>#sidebar { font-size: 12px; position: fixed; color: white; top: 227px; left: 90%; width: 9.5%; background-color: rgba(12,35,44,0.6); border: 2px solid #3D89A4; font-family: Minecraft; } .logininfotext { width: 100px; } .error { padding: 6px; border: 1px solid rgba(123, 29, 29, 0.7); border-radius: 4px; background-color: rgba(245, 83, 83, 0.5); font-size: 10px; color: #916E6E; } </code></pre> <p>Javascript/JQuery:</p> <pre><code>//saves all userdata of current session to the user object. function saveuserdata() { var session_user_data = JSON.parse(get_data("#sidebar", "php/sqlquery.php", "session_user_data")); user.username=session_user_data[0]; user.password=session_user_data[1]; var session_user_data2=JSON.parse(get_data("#sidebar", 'php/sqlquery.php', 'Userdata', user.username)); user.picture=session_user_data2[0]['Picture']; user.posts=session_user_data2[0]['Posts']; //reprints the login form, supposedly adding whatever html to the end I want for error support function loginform(extrastring) { var loginform = "&lt;p&gt;Login&lt;/p&gt;&lt;form id='login'&gt;&lt;input class='logininfotext' type='text' id='login_username' placeholder='username'/&gt;&lt;/br&gt;"; loginform += "&lt;input class='logininfotext' type='password' id='login_password' placeholder='password'/&gt;&lt;/br&gt;&lt;input id='loginbutton' type='submit' value='login'&gt;&lt;/form&gt;"; if (typeof(extrastring)=='string') { loginform += extrastring; } $("#sidebar").html(loginform); } $('#sidebar').submit(function() { var test=true //normally, this would be a call to php to check if the user logged in successfully or not. I know my php is working, but my problem is I don't want the page reloading user.username=$('#login_username').val(); user.password=$('#login_password').val(); if (test=true) { saveuserdata(); $("#sidebar").html("&lt;p class='username'&gt;"+user.username+"&lt;/p&gt;&lt;img width='125px' height='125px' src='"+user.picture+"'/&gt;&lt;p&gt;Posts: "+user.posts+"&lt;/td&gt;&lt;div id='logout'&gt;logout&lt;/div&gt;"); } else { loginform("&lt;p class='error'&gt;Username or Password incorrect!&lt;/p&gt;"); } return false; }); </code></pre> <p>Help is much appreciated. I realize it is hard to figure out just what is happening here. If you want to see the full thing, be my guest: <a href="http://lampitosgames.com/forum/index.php" rel="nofollow">http://lampitosgames.com/forum/index.php</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload