Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to validate form with ajax. Same code, different behaviour
    text
    copied!<p>I'm working on a project in my dev site that has exactly the same code as my production one.</p> <p>It's a simple form validation using ajax. Here's the code for dispuser.php:</p> <pre><code>$username = protect($_POST['user_name']); $dispuser = new user(); $dispuser-&gt;username = $username; $res = $dispuser-&gt;get("all"); $num = mysql_num_rows($res); if ($num&gt;0) { echo "no"; } else { echo "yes"; } </code></pre> <p>Here's the javascript code:</p> <pre><code>$(document).ready(function() { $("#username").blur(function() { $("#msgbox").removeClass().addClass('messagebox').text('Verificando...').fadeIn("slow"); $.post("./dispuser.php",{ user_name:$(this).val() } ,function(data) { if(data=='no') { document.getElementById("submitBT").disabled = true; $("#msgbox").fadeTo(200,0.1,function() { $(this).html('Not available').addClass('messageboxerror').fadeTo(900,1); }); } else { $("#msgbox").fadeTo(200,0.1,function() { document.getElementById("submitBT").disabled = false; $(this).html('Available!').addClass('messageboxok').fadeTo(900,1); }); } }); }); }); </code></pre> <p>And here's the html code:</p> <pre><code>&lt;td&gt;&lt;label for="username"&gt;Usuário: &lt;/label&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="username" id="username" /&gt;&lt;/td&gt; &lt;td&gt;&lt;span id="msgbox" style="display:none; no-padding;"&gt;&lt;/span&gt;&lt;/td&gt; </code></pre> <p>I already tracked the response with firebug and everything is ok! (returns "yes" when user available and "no" when not available.</p> <p>I have the exact same code in: <code>pp.atoanavida.com.br/registro.php</code> and in <code>www.pesometro.com.br/registro.php</code></p> <p>You can try with user "atoanavida". It's not available and both databases are exactly the same.</p> <p>My problem: My production site is working OK, showing the right message when the user is/isn't available. On my dev site, which has the same code, the script always shows "user available".</p>
 

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