Note that there are some explanatory texts on larger screens.

plurals
  1. POCheck username JQuery Ajax
    primarykey
    data
    text
    <p>I have the following ajax call </p> <pre><code> $.ajax( { type: "POST", url: "Utilities/CheckUsername.php", data: "un="+ un, success: function(data) { if(data!=1) { $('#mike').html(data); return false; } } }); </code></pre> <p>I want the page to stay if the username is taken, else redirect to whats in the action attribute of the for.</p> <p>Obviously this isn't working. But why? I would like to not use <code>preventdefault</code>, so that I could get a better understanding of where the problem and solution is.</p> <p>EDIT: The server code</p> <pre><code>&lt;?php $seed = 'n48sma94r98'; $email = $_POST['un']; $mysqli = new mysqli('localhost','uml','uml','uml'); if (!$mysqli) { printf("Can't connect to MySQL Server. Errorcode: %s\n", mysqli_connect_error()); exit; } $query = "Select User_Email as Email from user2 where User_Email = AES_ENCRYPT('$email','$seed') "; $result = $mysqli-&gt;query($query); if($result-&gt;num_rows &gt; 0) { echo "1"; } else { echo "2"; } ?&gt; </code></pre> <p>The entire form minus the meta:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Untitled&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="my.css"&gt; &lt;script type="text/javascript" src="Resources/js/jquery-1.4.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt;$(document).ready(function(){ $("#login").submit(function() { var un = $('#username').val(); $.ajax( { type: "POST", url: "Utilities/CheckUsername.php", data: "un="+ un, success: function(data) { if(data!=1) { $('#mike').html(data); return false; } } }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="login" id="login" method="post" action="dsds.html"&gt; UserName&lt;input type="text" name="username" id="username"value=""&gt; Password&lt;input type="text" name="password" id="password" value=""&gt; Password Again&lt;input type="text" name="passwordagain" id="passwordagain" value=""&gt; &lt;input type="hidden" name="NewClass" id="NewClass" value="true"&gt; &lt;input type="submit" name="submit" id="submit" value="submit"&gt; &lt;/form&gt; &lt;span id = "mike"&gt;&lt;/span&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    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