Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP & AJAX Getting response but not loading new page
    text
    copied!<p>Hi am passing a username and password to a php page using AJAX, once it has identified the username and password exists I want to load the page main.html.</p> <p>At the moment when i submit the form, i get the response true back, this shows above the form in the location of the error message label, but it doesn't load the main.html page.</p> <p>I am newbie and so not really sure where i have gone wrong, I have run the code in the chrome web developer Console but it isn't showing any problems and was hoping somebody could point me in the right direction.</p> <p>URL to the page : <a href="http://goo.gl/7QGrnr" rel="nofollow">http://goo.gl/7QGrnr</a></p> <p>HTML Code</p> <pre><code> &lt;label id="errorMessage"&gt;&lt;/label&gt; &lt;form name="login" class="login"&gt; &lt;input name="username" type="text" placeholder="Username"/&gt; &lt;input name="password" type="text" placeholder="Password"/&gt; &lt;input type="submit" name="login" class="login" value="Login" id="orange"/&gt; &lt;/form&gt; </code></pre> <p>AJAX Code</p> <pre><code>$(document).ready(function(){ $('form.login').submit(function () { var username = $("[name='username']").val(); var password = $("[name='password']").val() // ... $.ajax({ type: "POST", url: "login.php", data: "username="+ username +"&amp; password="+ password, success: function(response){ if(response == 'true') { window.location.href='main.html'; } else { $("#errorMessage").html(response); } } }); return false; }); }); </code></pre> <p>PHP Code</p> <pre><code> $username = mysql_real_escape_string($_POST['username']); $password = md5(mysql_real_escape_string($_POST['password'])); if(!empty($username) &amp;&amp; !empty($password)) { $result = mysql_query("SELECT * FROM users WHERE username='$username' and password ='5d503cf3064551d1bae24d5e2aaedbd9'"); $num_rows01 = mysql_num_rows($result); if($num_rows01 === 1) { echo 'true'; } else { echo 'false'; } } </code></pre>
 

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